开发者

jQuery if checkbox is not checked issue [duplicate]

This question already has answers here: Closed 10 years ago.

Possible Duplicate:

Check checkbox checked property using jQuery

I am having an issue picking up when a checkbox is not checked.

Here is my sample code:

$(".get-the-look ul input").click(function(){
    if("this:checked") {
        var product = $(this).attr('alt');
        $("#bob div").re开发者_StackOverflowmove('.'+product);
    } else {
        alert('asdasd');
    }
});

But the alert (if the checkbox isn't checked) never fires... The 'else' never kicks in no matter what state the checkbox is in?

I don't see where I am going wrong.


you can't pass this:checked as a string - it won't work as it will be interpreted as a string and always evaluate to true

use $(this).is(':checked') instead


The string "this:checked" will always evaluate to TRUE. Try this.checked instead, i.e., evaluate the property checked on this:

if(this.checked) { ...
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜