Check if checkbox is checked with jQuery

后端 未结 23 3060
忘了有多久
忘了有多久 2020-11-21 23:12

How can I check if a checkbox in a checkbox array is checked using the id of the checkbox array?

I am using the following code, but it always returns the count of ch

23条回答
  •  借酒劲吻你
    2020-11-21 23:52

    The most important concept to remember about the checked attribute is that it does not correspond to the checked property. The attribute actually corresponds to the defaultChecked property and should be used only to set the initial value of the checkbox. The checked attribute value does not change with the state of the checkbox, while the checked property does. Therefore, the cross-browser-compatible way to determine if a checkbox is checked is to use the property

    All below methods are possible

    elem.checked 
    
    $(elem).prop("checked") 
    
    $(elem).is(":checked") 
    

提交回复
热议问题