HTML

1个成员

HTML元素 - option

发表于 2017-02-01 2854 次查看

定义

表示 SELECT 元素中的一个选项。

Denotes one choice in a SELECT element.

注释

在 Internet Explorer 5 及以后版本中,OPTION 元素是 all 集合的一部分。而在较早版本中,你只能通过 SELECT 元素的 options 集合获得对这些元素的访问。

你只能在与 OPTION 位于同一窗口的 SELECT 元素里添加 OPTION 元素。

除了 background-color 和 color,通过 style 为 option 元素指定的样式设置都将被忽略。此外,直接应用到单个 options 的样式将覆盖应用到 SELECT 元素容器的样式。

此元素在 Internet Explorer 3.0 及以上版本的 HTML 和脚本中可用。

此元素是一个块元素。

此元素不需要关闭标签。

As of Internet Explorer 5 and later, the OPTION elements are part of the all collection. For earlier versions, you can gain access to these elements by applying the options collection to the SELECT element.

You can add OPTION elements only to a SELECT element that is located in the same window where the OPTION elements are created.

Except for background-color and color, style settings applied through the style object for the option element are ignored. In addition, style settings applied directly to individual options override those applied to the containing SELECT element as a whole.

This element is available in HTML and script as of Internet Explorer 3.0.

This element is a block element.

This element does not require a closing tag.

示例代码

下面的例子使用 OPTION 元素创建了下拉列表框中的单个项目。

<SELECT ID="oCars" SIZE="1" onchange="fnChange()">
<OPTION VALUE="1">宝马
<OPTION VALUE="2">保时捷
<OPTION VALUE="3" SELECTED>大奔
</SELECT>
<TEXTAREA ID="oData"></TEXTAREA>

下面的例子使用 options 集合将列表框中选中的项目追加到文本区域中。

<SCRIPT LANGUAGE="JScript">
function fnChange(){
oData.value+=oCars.options[oCars.selectedIndex].text + "\n";
}
</SCRIPT>
发表回复
你还没有登录,请先登录注册