Original address: Http://wenku.baidu.com/view/0d30474bfe4733687e21aa31.html
I want to create a friend sending function module today, but I don't know much about it.CheckboxAndJSCombined with the attributes and functions, I found some examples on the Internet for analysis.
<Script language = "JavaScript"> Function chk () { VaR dd = Document. getelementsbytagname ("input ") For (I = 0; I <dd. length; I ++ ){ If (Dd [I]. type = 'checkbox' & dd [I]. ID! = "XX "){ Dd [I]. Checked = Document. getelementbyid ("XX"). checked; } } } </SCRIPT> <Input type = "checkbox" name = "checkbox1" id = "XX" value = "checkbox" Onclick = "chk ()"/> <Input type = "checkbox" name = "checkbox2" value = "checkbox"/> <Input type = "checkbox" name = "checkbox3" value = "checkbox"/> <Input type = "checkbox" name = "checkbox4" value = "checkbox"/> <Input type = "checkbox" name = "checkbox5" value = "checkbox"/> <Input type = "checkbox" name = "checkbox" value = "checkbox"/> <Input type = "checkbox" name = "checkbox6" value = "checkbox"/>
This sectionCodeWhen the first option is selected, all the selection boxes are automatically selected. However, it is normal when other boxes are selected.Checked.
first, explain checkbox attributes, checkbox. checked front: CHEC Kbox object, followed by a method, which indicates that the box is selected.
HereJSThe Code containsGetelementbyid ()YesGetelementbytagname (). The first method is usually accurate positioning.IDTo directly find the object. The second method is to traverse objects and identify objects by tag names. Finally, the traversal objects are used for conditional filtering.
This makes it easy to understand the aboveJSThe code in it makes sense.
<Input type = "checkbox" name = "checkbox1" id = "XX" value = "checkbox" onclick = "chk ()"/> //First, you must select the first box to loadJSScriptChk ()------------------------------------------------------------------
<Script language = "JavaScript"> Function chk () { VaR dd = Document. getelementsbytagname ("input ")//Use the tag name to find allInputObject; For (I = 0; I <dd. length; I ++ ){ If (Dd [I]. type = 'checkbox' & dd [I]. ID! = "XX "){//Judge whether the retrieved object isCheckboxControl, and cannot be the first selection box"XX"; Dd [I]. Checked = Document. getelementbyid ("XX"). Checked ;//When the first selection box"XX"Selected, Object[I]Also selected. } } } </SCRIPT>