HTML元素 - select

定义

表示一个列表框或者一个下拉框。

Denotes a list box or drop-down list.

注释

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

此元素是窗口控件,不支持 z-index 或者 zIndex 属性。

此元素是内嵌元素。

此元素需要关闭标签。

The SELECT element is available in HTML and script, as of Internet Explorer 3.0.

This element is a windowed control and does not support the z-index attribute or zIndex property.

This element is an inline element.

This element requires a closing tag.

示例代码

下面的例子使用 SELECT 元素创建了一个下拉列表框。

This example uses the SELECT element to create a drop-down list box.

<SELECT NAME="Cats" SIZE="1">
<OPTION VALUE="1">Calico
<OPTION VALUE="2">Tortie
<OPTION VALUE="3" SELECTED>Siamese
</SELECT>

 

下面的例子使用 select 元素创建了多项选择列表框,方法是设置了 SIZE 和 MULTIPLE 标签属性。要获得多项选择列表框的选中选项,则须遍历 options 集合并检查 SELECTED 是否被设为 true。

This example uses the select element to create a multi-select list box by setting the SIZE and MULTIPLE attributes. To retrieve the selected options for a multi-select list box, iterate through the options collection and check to see where SELECTED is set to true.

<SELECT ID="oSelect" NAME="Cars" SIZE="3" MULTIPLE>
<OPTION VALUE="1" SELECTED>BMW
<OPTION VALUE="2">Porsche
<OPTION VALUE="3" SELECTED>Mercedes
</SELECT>

 

下面的例子在上面创建的 SELECT 列表的底部添加了一个新选项。新选项的构造程序也可在 Microsoft JScript? 中使用。

This example adds a new option to the end of the SELECT list created above. The new Option constructor can also be used in Microsoft JScript.

<SCRIPT LANGUAGE="JScript">
var oOption = document.createElement("OPTION");
oOption.text="Ferrari";
oOption.value="4";
oSelect.add(oOption);
</SCRIPT>

另见

option