This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
这个问题已经过大量编辑,
我需要使用一个重置按钮来重置此代码,以便可以从currentItem 1中再次使用它,问题是仅重置当前项目,并且突出显示的列表项仍被设置为好像当前项不在1一样。

 var stuff = new Array();
stuff["li_1"]="ext_1";
stuff["li_2"]="hc_1";
stuff["li_3"]="ext_2";
stuff["li_4"]="ext_3";
stuff["li_5"]="hc_2";
stuff["li_6"]="ext_4";
stuff["li_7"]="hc_3";
stuff["li_8"]="ext_5";
stuff["li_9"]="hc_4";
stuff["li_10"]="ext_6";
stuff["li_11"]="hc_5";
var currentItem=1;
var extWrong=false;
var extCorrect=false;
var hcWrong=false;
var hcCorrect=false;

$(document).ready(function(e) {
    //document.ontouchmove = function(e){ e.preventDefault(); }
    $('#li_1').draggable({revert:true} );
    $("#li_1").addClass("highlighted");
    $('.drop_area').droppable({
         tolerance:"pointer",
         drop:function (event, ui) {
            var tmpID=$(ui.draggable).attr("id");
            var droppableID = $(this).attr("id");
            var audioToPlay="";
            $("#" + tmpID).hide();
            $("#" + stuff[tmpID]).show();
            $("#" + stuff[tmpID]).addClass("highlighted");

            currentItem++;

            var dragType=tmpID.split("_")[1];
            dragType=(dragType=="1" || dragType=="3" ||dragType=="4" ||dragType=="6" ||dragType=="8" ||dragType=="10")?"ext":"hc";
            var dropType=droppableID=="extreme_thoughts"?"ext":"hc";

            if(dragType=="ext" && dropType=="ext"){
                    audioToPlay=extCorrect==false?"IntDragDrop_ExtremeCorrect.mp3":"ding.mp3";
                    extCorrect=true;
            }else if(dragType=="ext" && dropType=="hc"){
                    audioToPlay=extWrong==false?"IntDragDrop_ExtremeIncorrect.mp3":"pop4c.mp3";
                    extWrong=true;
            }else if(dragType=="hc" && dropType=="hc"){
                    audioToPlay=hcCorrect==false?"IntDragDrop_HealthyCorrect.mp3":"ding.mp3";
                    hcCorrect=true;
            }else if(dragType=="hc" && dropType=="ext"){
                audioToPlay=hcWrong==false?"IntDragDrop_HealthyIncorrect.mp3":"pop4c.mp3";
                    hcWrong=true;

            }
            playSound(audioToPlay,"#" + stuff[tmpID],"#" + "li_" + currentItem);

            }

    });


这是我坏了的按钮。

$("#restart").click(function(){
  currentItem=1;
    var extWrong=false;
    var extCorrect=false;
    var hcWrong=false;
    var hcCorrect=false;
  $("#ext_1,#ext_2,#ext_3,#ext_4,#ext_5,#ext_6,#hc_1,#hc_2,#hc_3,#hc_4,#hc_5,#congrats").hide()
  $("#li_1,#li_2,#li_3,#li_4,#li_5,#li_6,#li_7,#li_8,#li_9,#li_10,#li_11,#hide_me,#hide_me2").show()
  $("#li_2,#li_3,#li_4,#li_5,#li_6,#li_7,#li_8,#li_9,#li_10,#li_11").removeClass("highlighted");
    alert(currentItem)
});

最佳答案

您的作业中有错别字,您正在执行currentItem==1而不是currentItem=1;

09-30 17:00
查看更多