gpt4 book ai didi

javascript - 数字按正确顺序显示按钮

转载 作者:行者123 更新时间:2023-12-04 07:13:55 26 4
gpt4 key购买 nike

我正在做一个元素,你必须把上面的数字 1/9 按正确的顺序排列。
例如:1-6-3
当数字按正确顺序放置时,将出现一个按钮以继续下一页。有人可以帮我吗?

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("Text", ev.target.id);
}

function drop(ev) {
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
ev.preventDefault();
}
body {
background-color: #cccccc;
}

.content-size {
height: 300px;
width: 300px;
position: fixed;
left: 50%;
top: 40%;
transform: translate(-50%, -50%);
background-color: #3e3e3e;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
border: 2px solid #3e3e3e;
}

.picure-1-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-2-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-3-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-4-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-5-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-6-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-7-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-8-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-9-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

#code-number-1 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-1:hover {
color: #fdfdfda3;
}

#code-number-2 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-2:hover {
color: #fdfdfda3;
}

#code-number-3 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-3:hover {
color: #fdfdfda3;
}

#code-number-4 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-4:hover {
color: #fdfdfda3;
}

#code-number-5 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-5:hover {
color: #fdfdfda3;
}

#code-number-6 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-6:hover {
color: #fdfdfda3;
}

#code-number-7 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-7:hover {
color: #fdfdfda3;
}

#code-number-8 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-8:hover {
color: #fdfdfda3;
}

#code-number-9 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-9:hover {
color: #fdfdfda3;
}

.numbers-3 {
height: 70px;
width: 300px;
position: fixed;
left: 50%;
top: 79%;
transform: translate(-50%, -50%);
background-color: #3a3939;
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
border: 2px solid #3e3e3e;
}

a {
color: #ffffff61;
text-decoration: none;
font-weight: bold;
font-size: 13px;
font-family: arial;
cursor: pointer;
}

.reset {
height: 50px;
width: 150px;
position: fixed;
left: 50%;
top: 95%;
transform: translate(-50%, -50%);
background-color: #444444f2;
text-align: center;
line-height: 50px;
border-radius: 10px;
border: 1px solid #d6d6d6;
}

.reset:hover {
background-color: #353535f2;
}

#code-1 {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}

#code-2 {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}

#code-3 {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}
<div class="content-size">
<div class="picure-1-box">
<div draggable="true" id="code-number-1" ondragstart="drag(event)">
1
</div>
</div>
<div class="picure-2-box">
<div draggable="true" id="code-number-2" ondragstart="drag(event)">
2
</div>
</div>
<div class="picure-3-box">
<div draggable="true" id="code-number-3" ondragstart="drag(event)">
3
</div>
</div>
<div class="picure-4-box">
<div draggable="true" id="code-number-4" ondragstart="drag(event)">
4
</div>
</div>
<div class="picure-5-box">
<div draggable="true" id="code-number-5" ondragstart="drag(event)">
5
</div>
</div>
<div class="picure-6-box">
<div draggable="true" id="code-number-6" ondragstart="drag(event)">
6
</div>
</div>
<div class="picure-7-box">
<div draggable="true" id="code-number-7" ondragstart="drag(event)">
7
</div>
</div>
<div class="picure-8-box">
<div draggable="true" id="code-number-8" ondragstart="drag(event)">
8
</div>
</div>
<div class="picure-9-box">
<div draggable="true" id="code-number-9" ondragstart="drag(event)">
9
</div>
</div>
</div>
<div class="numbers-3">
<div id="code-1" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
<div id="code-2" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
<div id="code-3" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
</div>
<div class="reset">
<a href=".">Reset</a>
</div>

最佳答案

我使用数组和 parseInt 来编辑数组。这有点粗略,但它有效。我将代码设置为 1-6-3。它不会创建一个按钮来继续;它只是验证代码。

function allowDrop(ev) {
ev.preventDefault();
}

function drag(ev) {
ev.dataTransfer.setData("Text", ev.target.id);
}

var input_code = [-1, -1, -1];

function drop(ev) {
var data = ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
input_code[parseInt(ev.target.id.split('-')[1], 10)-1] = parseInt(document.getElementById(data).innerText, 10);
if (input_code.toString() === [1, 6, 3].toString()) {
console.log("correct");
// append your button
}
ev.preventDefault();
}
body {
background-color: #cccccc;
}

.content-size {
height: 300px;
width: 300px;
position: fixed;
left: 50%;
top: 40%;
transform: translate(-50%, -50%);
background-color: #3e3e3e;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
border: 2px solid #3e3e3e;
}

.picure-1-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-2-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-3-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 20%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-4-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-5-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-6-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-7-box {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-8-box {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

.picure-9-box {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 80%;
transform: translate(-50%, -50%);
background-color: #3a3a3a;
border-radius: 35px;
}

#code-number-1 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-1:hover {
color: #fdfdfda3;
}

#code-number-2 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-2:hover {
color: #fdfdfda3;
}

#code-number-3 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-3:hover {
color: #fdfdfda3;
}

#code-number-4 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-4:hover {
color: #fdfdfda3;
}

#code-number-5 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-5:hover {
color: #fdfdfda3;
}

#code-number-6 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-6:hover {
color: #fdfdfda3;
}

#code-number-7 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-7:hover {
color: #fdfdfda3;
}

#code-number-8 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
border-radius: 35px;
}

#code-number-8:hover {
color: #fdfdfda3;
}

#code-number-9 {
font-size: 15px;
font-family: arial;
text-align: center;
line-height: 50px;
color: #868686;
font-weight: bold;
cursor: grab;
}

#code-number-9:hover {
color: #fdfdfda3;
}

.numbers-3 {
height: 70px;
width: 300px;
position: fixed;
left: 50%;
top: 79%;
transform: translate(-50%, -50%);
background-color: #3a3939;
border-bottom-left-radius: 15px;
border-bottom-right-radius: 15px;
border: 2px solid #3e3e3e;
}

a {
color: #ffffff61;
text-decoration: none;
font-weight: bold;
font-size: 13px;
font-family: arial;
cursor: pointer;
}

.reset {
height: 50px;
width: 150px;
position: fixed;
left: 50%;
top: 95%;
transform: translate(-50%, -50%);
background-color: #444444f2;
text-align: center;
line-height: 50px;
border-radius: 10px;
border: 1px solid #d6d6d6;
}

.reset:hover {
background-color: #353535f2;
}

#code-1 {
height: 50px;
width: 50px;
position: fixed;
left: 20%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}

#code-2 {
height: 50px;
width: 50px;
position: fixed;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}

#code-3 {
height: 50px;
width: 50px;
position: fixed;
left: 80%;
top: 50%;
transform: translate(-50%, -50%);
background-color: #525252bf;
border-radius: 5px;
}
<div class="content-size">
<div class="picure-1-box">
<div draggable="true" id="code-number-1" ondragstart="drag(event)">
1
</div>
</div>
<div class="picure-2-box">
<div draggable="true" id="code-number-2" ondragstart="drag(event)">
2
</div>
</div>
<div class="picure-3-box">
<div draggable="true" id="code-number-3" ondragstart="drag(event)">
3
</div>
</div>
<div class="picure-4-box">
<div draggable="true" id="code-number-4" ondragstart="drag(event)">
4
</div>
</div>
<div class="picure-5-box">
<div draggable="true" id="code-number-5" ondragstart="drag(event)">
5
</div>
</div>
<div class="picure-6-box">
<div draggable="true" id="code-number-6" ondragstart="drag(event)">
6
</div>
</div>
<div class="picure-7-box">
<div draggable="true" id="code-number-7" ondragstart="drag(event)">
7
</div>
</div>
<div class="picure-8-box">
<div draggable="true" id="code-number-8" ondragstart="drag(event)">
8
</div>
</div>
<div class="picure-9-box">
<div draggable="true" id="code-number-9" ondragstart="drag(event)">
9
</div>
</div>
</div>
<div class="numbers-3">
<div id="code-1" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
<div id="code-2" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
<div id="code-3" ondragover="allowDrop(event)" ondrop="drop(event)"></div>
</div>
<div class="reset">
<a href=".">Reset</a>
</div>

关于javascript - 数字按正确顺序显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68897116/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com