Home > Article > Web Front-end > How to use datalist in html
The <datalist> element in HTML is used to provide a predefined set of options to help users quickly select values in the input box. Its usage consists of the following steps: Create a <datalist> element containing one or more <option> elements, each <option> specifying an option. Within an <input> element, use the list attribute to specify the id of the associated <datalist> element. When the user inputs in the <input> element, the <datalist> element will be displayed as in the input
##HTML
datalist element is used to provide a predefined set of options so that users can quickly and easily select values in the input box. Its usage is described in detail below:
Usage:
##<datalist> The element contains one or more <option>
elements, each <option>
element specifies an option.
<code class="html"><input list="browsers" placeholder="选择浏览器">
<datalist id="browsers">
<option value="Firefox">
<option value="Chrome">
<option value="Safari">
<option value="Edge">
</datalist></code>
<datalist>
. The list
attribute value must be the same as the id
attribute value of the <datalist>
element.
Each
<option> element contains a value
attribute that specifies the value of the option value. As the user types in the <input>
element, the <datalist>
element displays options that match the input.
##<datalist>
elements are used together.
<datalist> elements. The
<input> attribute to be associated with the
<datalist> element.
Convenient input:
The above is the detailed content of How to use datalist in html. For more information, please follow other related articles on the PHP Chinese website!