Option selected 属性

定义和用法

selected 属性设置或返回选项的选定状态。

另请参阅:

HTML 参考手册:HTML <option> selected Atrybutu

HTML 参考手册:HTML <option> Tag

实例

例子 1

将下拉列表中的选定选项更改为 "orange":

document.getElementById("orange").selected = true;

亲自试一试

例子 2

查看下拉列表中的 "banana" 选项是否被选中:

var x = document.getElementById("banana").selected;

亲自试一试

语法

返回 selected 属性:

optionObject.selected

设置 selected 属性:

optionObject.selected = true|false

Attribute Value

Value Description
true|false

Specifies whether the option should be selected in the dropdown list.

  • true - The option is selected
  • false - Default. The option is not selected

Technical Details

Return Value: Boolean Value, returns true if the option is selected; otherwise returns false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support