The code is as follows |
Copy Code |
<input type= "checkbox" name= "checkbox" value= "" id= "checkbox"/> |
The JavaScript processing checkbox is summarized as follows
1,javascript checked checkbox form
(1) Get the Form object
(2) Set the checked value of the Form object, true to tick the check or reverse the selection
The code is as follows |
Copy Code |
document.getElementById ("checkbox"). Checked = True |
2,javascript Get all CheckBox form objects on page
(1) root tag tagname get all input objects
(2) If the object type is a checkbox, the checkbox form
The code is as follows |
Copy Code |
var checkbox = document.getelementsbytagname ("input"); For (Var i=0,length=checkbox. length;i<length;i++) { if (Checkbox.type = = ' checkbox ') { CheckBox form } } |
3, the realization of the checkbox form adjacent to the element click Tick, click "Select" CheckBox form
The code is as follows |
Copy Code |
<input type= "checkbox" name= "checkbox" value= "id= checkbox"/><span> selected </span>
var checkbox = document.getElementById ("checkbox"); var nextobj = checkbox.nextsibling; Nextobj.onclick = function () { This.previousSibling.click (); } |
Note the application of two adjacent elements nextsibling and previoussibling.
Resources
XML DOM nextSibling Property
The NextSibling property returns the element immediately following an element (in the same tree hierarchy).
If there is no this node, the property returns NULL.
Syntax: nodeobject.nextsibling
XML DOM PreviousSibling Property
The PreviousSibling property returns the node immediately preceding a node (at the same tree level)
If there is no this node, the property returns NULL.
Syntax: nodeobject.previoussibling