我觉得我在这里错过了一些简单的东西,但在我的生活中看不到它。 'if'部分工作正常,但'else'甚至没有被触发(控制台日志不会显示)。
代码本身用于简单的拖放操作,其中#answer2是#targetbox1的答案。
有什么想法吗?总共JS noob。
谢谢
$('.draggable').draggable({stack: "#page-lev2", revert: "invalid"});
$('#targetbox1').droppable({
drop: function( event, ui ) {
if(ui.draggable.is("#answer2")){
$(this).css("background", "url('img/lev2/targetAreaCorrect.svg') no-repeat");
$("#answer2").css("border", "none");
addToCorrect();
}
else{
console.log("why wont you work")
wrong();
}
}
});
function wrong() {
$("#lev2-intro").addClass("hide");
$("#lev2-wrong").removeClass("hide");
}
编辑:包含使用的HTML代码
<div id="answers">
<div id="answer1" class="draggable">
<p><span class="redThin">Roots</span></p>
</div>
<div id="answer2" class="draggable">
<p><span class="greenThin">Petals</span></p>
</div>
<div id="answer3" class="draggable">
<p><span class="blueThin">Leaf</span></p>
</div>
<div id="answer4" class="draggable">
<p><span class="darkpurpThin">Stem</span></p>
</div>
</div>
<div id="targets">
<div id="targetbox1" class="target"></div>
<div id="targetbox2" class="target "></div>
<div id="targetbox3" class="target moreMarg"></div>
<div id="targetbox4" class="target"></div>
</div>