开发者

Error with JQuery attribute checked

For some reason this is not working. Instead it thinks it should check the checkbox rather than find out if the box is checked. Can anyone see where I have g开发者_如何转开发one wrong.

if ($('#OPT2checked').attr('checked','checked')) {
    var OPT2checked = 'checked="checked"';
    } else {var OPT2checked = ''};

Any ideas?

Marvellous,


Try this :)

 if ($('#OPT2checked').is(':checked')) {
     // Your thing
 }


$('#OPT2checked').attr('checked','checked') sets the attribute 'checked' to 'checked'

$('#OPT2checked').attr('checked') returns the value of the checked attribute.

By the way, you should test if the checked attribute is defined and not if it has a specific value.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜