select
<select>
HTML<select> 元素是一种表单控件,可创建选项菜单。菜单内的选项为<option> , 可以由 <optgroup> 元素分组。选项可以被用户预先选择。
内容类别 | |
---|---|
允许的内容 | 零个或多个<option>或<optgroup>元素。 |
标记遗漏 | 没有,起始和结束标签都是强制性的。 |
允许父母 | 任何接受 phrasing content 的元素 |
允许ARIA角色 | menu |
DOM界面 | HTMLSelectElement |
属性
这个元素包含全局属性。
autofocus
HTML5这个属性能够让一个对象在页面加载的时候获得焦点. 在一个页面上下文中, 只有一个对象可以有这个属性,并且是布尔值(true 或者 false).
Firefox注意:
根据HTML5规范,大小的默认值应该是1; 然而,在实践中,这被发现打破了一些网站,目前没有其他的浏览器这样做,所以Mozilla选择继续返回0暂时与Firefox。
例子
<!-- The second value will be selected initially -->
<select name="select"> <!--Supplement an id here instead of using 'name'-->
<option value="value1">Value 1</option>
<option value="value2" selected>Value 2</option>
<option value="value3">Value 3</option>
</select>
结果
Value 1 Value 2 Value 3
注意
这个元素的内容是静态的,不可编辑。
规范
Specification | Status | Comments |
---|---|---|
HTML Living StandardThe definition of '<select>' in that specification. | Living Standard | |
HTML5The definition of '<select>' in that specification. | Recommendation | |
HTML 4.01 SpecificationThe definition of '<select>' in that specification. | Recommendation | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes)2 | (Yes) | 13 | (Yes) | (Yes) | (Yes)2 |
autofocus | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
disabled | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
form | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
multiple | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
name | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
required | (Yes) | (Yes) | 4 | 10 | (Yes) | (Yes) |
size | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes)1 2 | (Yes)2 | (Yes) | 14 | (Yes) | (Yes) | (Yes)2 |
autofocus | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
disabled | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
form | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
multiple | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
name | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |
required | (Yes) | (Yes) | (Yes) | 4 | No | (Yes) | (Yes) |
size | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |