[JS tutorial] After traversing the checkbox and submitting it, it is displayed as a hook.

Source: Internet
Author: User

 

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>

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.