Some practical experience of checkbox operation
- 2020-03-29 23:52:40
- OfStack
The checkbox looks simple, and sometimes it's a pain in the neck. What's so hard about it? !
So what?
After the experiment, the conclusion is as follows:
1. through $(selector).attr("checked") Can I get the actual value?
No . checkbox After being selected once, the result is always checked
2. through $(selector).attr("checked", true) You can make checkbox To be selected ?
No You can try
So what?
After the experiment, the conclusion is as follows:
The following obj = document.getElementById("id")
1. Get the value: $(selector).is(":checked") or $(selector).prop(":checked") return true/false
2. Operation selection: obj.checked = true
3. The selected obj.checked = !obj.checked