A datalist with pre-defined options (connected to an <input> element):
<label for="browser">Choose your browser from the list:</label>
<input list="browsers" name="browser" id="browser">
<datalist id="browsers">
<option value="Edge">
<option value="Firefox">
<option value="Chrome">
<option value="Opera">
<option value="Safari">
</datalist>
Try it Yourself »
The <datalist>
tag specifies a list of pre-defined options for an <input> element.
The <datalist>
tag is used to provide an "autocomplete" feature for <input> elements. Users will see a drop-down list of pre-defined options as they input data.
The <datalist>
element's id attribute must be equal to the <input> element's list attribute (this binds them together).
The numbers in the table specify the first browser version that fully supports the element.
Element | |||||
---|---|---|---|---|---|
<datalist> | 20.0 | 10.0 | 4.0 | 12.1 | 9.5 |
The <datalist>
tag also supports the Global Attributes in HTML.
The <datalist>
tag also supports the Event Attributes in HTML.
HTML DOM reference: Datalist Object
Most browsers will display the <datalist>
element with the following default values:
datalist {
display: none;
}
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!