开发者

checkbox val not showing false

开发者 https://www.devze.com 2022-12-31 09:56 出处:网络
I have the follwoing code: $(\"input:checkbox\").live(\'click\', function() { alert($(this).val()); });

I have the follwoing code:

 $("input:checkbox").live('click', function() {
                          alert($(this).val());
});

True is shown if the checkbox is checked. However, if the checkbox is checked and I uncheck it, the value shown 开发者_运维百科is still true. How can I correct that? What is wrong with the code? Thanks


The value of a checkbox is always the same. You need to see if it is checked or not.

….attr('checked');


this.checked //true/false - not jquery
$(element).checked //does not work
$(element).attr('checked') //checked/NULL *
$(element).is(':checked') //true/false

*note that <input TYPE=CHECKBOX CHECKED=CHECKED> returns in both checked/unchecked state checked

0

精彩评论

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