JavaScript Reference/Javascript Properties/defaultSelected
Содержание
"defaultSelected" Example
<!--
Example revised from
The Web Programmer"s Desk Reference
by Lazaro Issi Cohen and Joseph Issi Cohen
ISBN: 1593270119
Publisher: No Starch Press 2004
-->
<html>
<body>
<form id="myF"><select name="select">
<option value="1">Item 1</option>
<option value="2">Item 2</option>
<option id="option3" value="3">Default selected Option</option>
<script language="JavaScript">
document.getElementById("option3").defaultSelected = true;
var n = document.getElementById("option3").innerText;
function function1() {
alert("Default selected Option label:\n"+"""+n+""");
document.getElementById("myF").reset();
}
</script>
<option value="4">Item 4</option>
<option value="5">Item 5</option>
</select>
</form>
<input type="button" value="Click here" onclick="function1();">
</body>
</html>
"defaultSelected" is applied to
+----------------+--------------------------------------------------------------+
| Applied_To |<option> |
+----------------+--------------------------------------------------------------+
"defaultSelected" Possible Values
Possible Values
true
false.
"defaultSelected" Syntax and Note
Note:
Read and write property.
Sets the element selected state when the page is loaded.
Syntax:
document.getElementById("optionID").defaultSelected = value
document.all.optionID.defaultSelected = value // IE only