这个$ .inArray方法有什么问题?

时间:2015-07-07 05:55:21

标签: jquery arrays

在下面的代码中向底部我正在检查[number1, number2, number1+ number2]是否在数组wrongQs内是否为int推送数组,[number1, number2, number1+ number2]wrongQs

    $(document).ready( function(){

        var wrong = 0
        wrongQs = []
        clicked = false

         number1 = ~~(Math.random() * 10);
         number2 = ~~(Math.random() * 10);
        $(".numbers").children().remove()
        $(".numbers").html("<div>" + number1 +"</div><div>" + number2 + "</div>")

        $("button.go").on('click' , function(e){
            clicked = true
            console.log($(".input").val()," " ,(number1 + number2))
            //alert(+$(".input").val())
            if(+$(".input").val() == (number1 + number2)){
                 number1 = ~~(Math.random() * 10);
                 number2 = ~~(Math.random() * 10);
                $(".numbers").children().remove()
                $(".numbers").html("<div>" + number1 +"</div><div>" + number2 + "</div>")
            }else{
                clicked  = true
                wrong++
                console.log([number1, number2, number1+ number2])
                if( $.inArray([number1, number2, number1+ number2], wrongQs) == -1){
                    wrongQs.push([number1, number2, number1+ number2])
                    console.log("WrongQs Array " , wrongQs)
                    //wrong = 0
                }

            }
        })
    });

HTML:

<div class="numbers"></div>
<input class = "input"> <button class="go">Go</button>

0 个答案:

没有答案