jQuery条件语句被忽略

时间:2014-02-05 09:07:31

标签: jquery if-statement conditional-statements

我正在使用jQuery构建一个简单的Pick-Up-Jacks游戏,jackPick函数中有一个条件语句,无论它是否为true,都会被忽略。

为什么会发生这种情况?代码如下:

$(function(){

$("#button").click(function(){
    $("#something").animate({marginTop:"+=400px"}, 1200, comeBack());
    $("#something2").animate({marginTop:"+=400px"}, 2500);
    $("#something3").animate({marginTop:"+=400px"}, 3000);
});

function comeBack(){
    $("#something").animate({marginTop:"-=400px"}, 1200);
    $("#something2").animate({marginTop:"-=400px"}, 2500);
    $("#something3").animate({marginTop:"-=400px"}, 3000);
}

var i = 1;
function jackPick(bubble){
    var mt = $(bubble).css("margin-top"); 
        $(bubble).click(function(){
            if (mt != "400px"){
                $("p").html("<p>" +i+ "</p>");
                $(bubble).css({display:"none"});
                i++;
            }
        });
}

jackPick("#something");
jackPick("#something2");
jackPick("#something3");

});

0 个答案:

没有答案