English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

HTML 参考手册

HTML 标签大全

HTML: <option> Tag

在web表单中,HTML元素 <option> 用于定义在 <select>、<optgroup> 或 <datalist> 元素中包含的项。<option> 可以在弹出窗口和 html 文档中的其他项目列表中表示菜单项。

在线示例

创建带有 3 个选项的选择列表:

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>HTML option标签的使用(基础教程网 oldtoolbag.com)</title>
</head>
<body>
  <label for="tutorial_choice">Tutorials: </label>
  <select id="tutorial_choice">
    <option value="html">HTML</option>
    <option value="css">CSS</option>
    <option value="sql">SQL</option>
  </select>
</body>
</body>
</html>
测试看看 ‹/›

在此HTML5文档示例中,我们使用<select>标记创建了三个下拉值的列表-HTML,CSS和SQL。这些值将显示为下拉列表供用户选择。

浏览器兼容性

IEFirefoxOperaChromeSafari

大多数主流浏览器支持 <option> 标签。

标签定义及使用说明

<option> Tag defines an option (an entry) in a dropdown list.

The content of the <option> Tag is used as <select> or<datalist> One element usage.

Hint and Note

Note: The <option> Tag can be used without any attributes, but you usually need to use the value attribute, which indicates the content sent to the server.

Note: This tag should be used in conjunction with the select element; otherwise, it has no meaning.

Hint: If there are many list options, you can use the <optgroup> Tag to group related options.

Attribute

AttributeValueDescription
disableddisabledSpecify that this option should be disabled when first loaded.
labeltextDefine the label used when using <optgroup>.
selectedselectedSpecify that the option should be displayed as selected when it first appears in the list.
valuetextDefine the option value sent to the server.

Global Attributes

<option> Tag supports global attributes, see the complete attribute table HTML Global Attributes.

event attributes

<option> Tag supports all HTML Event Attributes.