开发者

Error with JQuery attribute checked

开发者 https://www.devze.com 2023-02-15 17:56 出处:网络
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.

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

精彩评论

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