摘要
:required
CSS 伪类 表示任意设置了required
属性的<input>
,<select>
, 或 <textarea>
元素。 这个伪类对于高亮显示在提交表单之前必须具有有效数据的字段非常有用。
注意::optional
伪类选中'可选的'表单字段。
语法
:required
例子
查看示例 :invalid
.
规范
Specification | Status | Comment |
---|---|---|
HTML Living Standard :required |
Living Standard | No change. |
HTML5 :required |
Recommendation | Defines the semantic regarding HTML and constraint validation. |
Selectors Level 4 :required |
Working Draft | No change. |
CSS Basic User Interface Module Level 3 :required |
Recommendation | Defines the pseudo-class, but not the associated semantic. |
浏览器兼容
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help!
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 10.0 | 4.0 (2) | 10 | 10.0 | 5.0 |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | ? | 4.0 (2) | 未实现 | 10.0 | 5.0 |