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
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn