Option 1 Option 1
Home >Web Front-end >Front-end Q&A >How to set up html drop-down box
HTML (Hypertext Markup Language) is a commonly used web development language, and drop-down boxes often need to be set up on web pages. A drop-down box is a commonly used interactive control, usually used to allow users to select one from multiple options. Setting up a drop-down box in HTML is very simple. This article will introduce how to set up an HTML drop-down box.
How to set up the HTML drop-down box
The HTML drop-down box is created through the
<select> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> …… </select>
Among them, the
The following is a simple drop-down box example:
<select> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
This code will generate a drop-down box containing three options.
Attributes of the drop-down box
By adding attributes, you can set various attributes of the drop-down box, such as selecting an option, setting the size of the drop-down box, etc.
The following are some commonly used attributes:
<option selected value="选项1">选项1</option>
The selected attribute can be used to set the default option of the drop-down box. If selected is not set attribute, the default option is the first option.
<select multiple> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
The multiple attribute enables the drop-down box to support multiple selections. Once multiple options are selected, you can hold down the Ctrl key and click on the options to deselect them.
<select size="5"> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
The size attribute can set the number of options that the drop-down box can display. If the number of options exceeds the specified number, a scroll bar appears to display additional options.
<select disabled> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
The disabled attribute can make the drop-down box unavailable and prohibit the user from making selections.
<select name="mySelect"> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
The name attribute is used to specify the name of the drop-down box. This attribute is usually used for form submission or accessing the drop-down box in JavaScript.
<select onchange="myFunction()"> <option value="选项1">选项1</option> <option value="选项2">选项2</option> <option value="选项3">选项3</option> </select>
The onchange attribute can be used to set the processing function after the drop-down box option is changed.
The above is the setting method of HTML drop-down box. I hope readers can master it.
The above is the detailed content of How to set up html drop-down box. For more information, please follow other related articles on the PHP Chinese website!