checkbox val not showing false
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
精彩评论