The native js operation checkbox is implemented with document.getelementbyid

  • 2020-03-26 21:25:47
  • OfStack

Jquery and the checked properties of the checkbox, about the control < Input type = "checkbox" > < / input>

1. After the page loads successfully, click to check or uncheck the checkbox. The checked property in the checkbox property will not change according to whether the checkbox is checked or not

2. In the onchange or onclick methods in the checkbox, the checked property value obtained by using jquery's attr method has nothing to do with whether it is checked or not

3, use document.getelementbyid ("checkbox_id").checked to get the value and whether or not to hook to, that is, and what you see is what you get

$("#checkbox_id").attr("checked") Input type = "checkbox" > < / input> In the checked case to, is not what you see is what you get

5. Use $("#checkbox:checked") to get the checked box

6, document.getelementbyid ("checkbox_id").checked=true, the checked property in the control is not displayed, what is seen

7. $("#checkbox_id").attr("checked", true), the checked property in the control is displayed

Js operation checkbox I recommend document.getelementbyid ("checkbox_id").checked, jquery operation checkbox is really annoying

Related articles: