我正在尝试编写一个 if else 语句来在一个类的 marginTop 为 -200px 的情况下单击另一个类时触发该类。
我试过使用这个 if 语句,但它不起作用:
if ($('.logintrigger').click() && $('.register').css('marginTop') === '-200px') {
$('.registertrigger').toggle(
function () {$('.register').stop().animate({'marginTop':'-0px'},200); $('#opencloseregister').css({'backgroundPosition':'-20px 0px'});}
);
}
有什么建议吗???
最佳答案
用 jquery 的正确 ifelse 示例制作了一个 jsfiddle。 http://jsfiddle.net/RQ75m/
$(".logintrigger").click(function(){
if( $(".register").css("margin-top") == "200px" ){
$(".registertrigger").show(); //toggle function here
return false; //so that the page doesn't refresh
} else {
$(".registertrigger").hide();
return false; //so that the page doesn't refresh
}
});
关于javascript - jQuery 在单击另一个类时切换一个类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10251468/