选择元素是否具有必需的属性?

2022-01-13 00:00:00 html-select attributes html

select 元素是否具有 required 属性?

Does the select element have the required attribute?

推荐答案

是的,您可以在 HTML5 中使用 required 属性.但请记住,第一个值应该为空.

Yes you can use required attribute in HTML5. But remember, first value should be empty.

<select required>
<option value="">Please select</option>
<option value="first">First</option>
</select>

这里有更多例子:

http://dev.w3.org/html5/spec-author-view/the-select-element.html#the-select-element

相关文章