Home > Web Front-end > JS Tutorial > A brief discussion on some operations of checkbox (practical experience)_Basic knowledge

A brief discussion on some operations of checkbox (practical experience)_Basic knowledge

WBOY
Release: 2016-05-16 17:13:41
Original
1178 people have browsed it

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? !

Copy code The code is as follows:

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:
Copy the code The code 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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template