Home >Web Front-end >JS Tutorial >js method to use DOM to set radio buttons, check boxes and drop-down menus_javascript skills
The example in this article describes how js uses DOM to set radio buttons, check boxes and drop-down menus. Share it with everyone for your reference. The specific implementation method is as follows:
1. Set radio buttons
The radio button in the form is It is a set of objects for the user to select, but only one can be selected at a time. Each one has a checked attribute. When one selection is true, the others become false.
Post an example first:
The radio button in the form is It is a set of objects for the user to select, but only one can be selected at a time. Each one has a checked attribute. When one selection is true, the others become false.
As can be seen from the above code, the id and name are different. Their names in a group of radio buttons are the same, and only one is selected. The id is bound to
In the code: the code to check the selected object is (when the chcked value of a certain item is true, the traversal ends)
2. Set multi-select box
Unlike radio buttons, checkboxes can select multiple options for processing at the same time. The checkbox before each email in the mailbox is a typical use
The check box principle is determined by using the Boolean value of the checked attribute. Parameters can be passed in the form of 0 and 1 to select all and not all.
3. Drop-down menu
Drop-down menu
Common attributes of drop-down menus:
Properties | Description |
length | Indicates the number of options |
selected | Boolean value, indicating whether |
SelectedIndex | The serial number of the selected option, -1 if no option is selected. For multi-select drop-down menus, return the first selected option Serial number, counting from 0 |
text | Text of option |
value | Option value |
type | The type of drop-down menu, single selection returns select-one, multiple selection returns select-multiple |
options | Get the array of options, for example: oSelectBox.options[2], which represents the third item of the drop-down menu oSelectBox |
②. When the drop-down menu is multi-select, the value is
③. Universal value (drop-down single selection and multiple selection)
I hope this article will be helpful to everyone’s JavaScript programming design.