Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 拖放检查_Javascript_Jquery_Html_Drag And Drop - Fatal编程技术网

Javascript 拖放检查

Javascript 拖放检查,javascript,jquery,html,drag-and-drop,Javascript,Jquery,Html,Drag And Drop,我想检查被丢弃的东西是否是正确的答案,当所有东西都被丢弃在正确的可丢弃区域时,它会发出警报 回答正确-drop1 DROPABLE&ans1 DRAGAGABLE项目和drop2 DROPABLE&ans2 DRAGABLE项目-一旦满足这两个条件,警报将弹出。然而,我似乎做不到 HTML: 我们必须将可拖动元素持久化,以便在连续删除时读取。愿它有帮助! var-arr=[]; var countOfItems=1; $ans1,ans2。可拖动{ 回复:无效, 光标:移动 }; $drop1,

我想检查被丢弃的东西是否是正确的答案,当所有东西都被丢弃在正确的可丢弃区域时,它会发出警报

回答正确-drop1 DROPABLE&ans1 DRAGAGABLE项目和drop2 DROPABLE&ans2 DRAGABLE项目-一旦满足这两个条件,警报将弹出。然而,我似乎做不到

HTML:


我们必须将可拖动元素持久化,以便在连续删除时读取。愿它有帮助! var-arr=[]; var countOfItems=1; $ans1,ans2。可拖动{ 回复:无效, 光标:移动 }; $drop1,drop2.dropable{ 贪婪:没错, drop:functionevent,ui{ var div=event.target.id; var元素=ui.draggable.attr'id'; arr.push{ “key”:div, “val”:元素 }; $+元素。addClass'someclass'; //如果类名为“someclass”的div大于所需的div数 如果$'div.someclass'.length>countOfItems{ var计数=假; $.eacharr,functioni,obj{ 如果obj.val==ans1&&obj.key==drop1 | | obj.val==ans2&&obj.key==drop2{ 计数=真; } }; 如果算上{ 成功 } 其他的 { 控制台故障 } } } }; .b1{ 高度:60px; 宽度:160px; 位置:绝对位置; 背景色:红色; 左:30px; 顶部:30px; } .b2{ 高度:60px; 宽度:160px; 位置:绝对位置; 背景色:红色; 左:280px; 顶部:30px; } ans1{ 背景颜色:黄色; 宽度:150px; 高度:50px; 位置:绝对位置; 边界半径:8px 8px 8px 8px; 左:30px; 顶部:120px; 盒子阴影:0px 0px 2px 1px黄色; } ans2{ 背景颜色:黄色; 宽度:150px; 高度:50px; 位置:绝对位置; 边界半径:8px 8px 8px 8px; 左:280px; 顶部:120px; 盒子阴影:0px 0px 2px 1px黄色; } 下降1 下降2 变化2 化学反应体系ans1
ans1的这些div是什么。你的问题和逻辑是不完整的也许它可以给你一些想法开始用一个,然后你将实施第二部分
//droppable area

<div id="drop1" class="b1" style="background-color: white; border: solid; height: 6vw; width: 13vw; border-radius: 7px">
</div>
<div id="drop2" class="b2" style="background-color: white; border: solid; height: 6vw; width: 13vw; border-radius: 7px">
</div>

//draggable item

<div id="ans2" style="background-color: white; border: solid; cursor: move; height: 6vw; width: 13vw; border-radius: 7px">
a change
</div>

<div id="ans1" style="background-color: white; border: solid; cursor: move; height: 6vw; width: 13vw; border-radius: 7px">
chemical reaction system
</div>
        $("#drop1, #drop2).droppable({
                drop: function (event, ui) {

                    var div = event.target.id;
                    var element = ui.draggable.attr('id');

                    if ((element === "ans1" && div === "drop1") && (element === "ans2" && div === "drop2")) {
                        alert("success");

                    }
    }
});