HTML DOM selected 屬性
定義和用法
selected 屬性可設(shè)置或返回選項(xiàng)的 selected 屬性的值。
該屬性設(shè)置選項(xiàng)的當(dāng)前狀態(tài),如果為 true,則該選項(xiàng)被選中。該屬性的初始值來自 <option> 的 selected 屬性。
語法
optionObject.selected=true|false
實(shí)例
本例可更改下拉列表中的被選選項(xiàng):
<html>
<head>
<script type="text/javascript">
function selectOrange()
{
document.getElementById("orange").selected=true;
}
</script>
</head>
<body>
<form>
Select your favorite fruit:
<select>
<option id="apple">Apple</option>
<option id="orange">Orange</option>
<option id="pineapple" selected="selected">Pineapple</option>
<option id="banana">Banana</option>
</select>
<br /><br />
<input type="button" onclick="selectOrange()" value="Select Orange">
</form>
</body>
</html>