Checkbox seems very simple, but sometimes it is a headache. What is difficult? Just google it and the code will come out, but is it really correct? !
1. Pass $(selector).attr("checked ")Can you get the actual value?
No, after the checkbox is selected once, the result is always checked
2. Can the checkbox be selected through $(selector).attr("checked", true)?
No, you can try
What should we do?
After experiments, the summary is as follows:
The following obj = document.getElementById("id")
1. Get the value: $(selector).is(":checked") or $(selector).prop(":checked") returns true/false
2. Operation selection: obj.checked = true
3. Inverse selection obj.checked = !obj.checked