defaultchecked
Radio defaultChecked 属性
定义和用法
defaultChecked 属性可返回 checked 属性的默认值。
如果单选按钮的默认状态是选中,则返回 true,否则返回 fasle。
语法
radioObject.defaultChecked
浏览器支持
所有主要浏览器都支持 defaultChecked 属性
实例
检测 "Blue" 选项是否默认选中:
<html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("blue").defaultChecked;
alert(x);
}
</script>
</head>
<body>
<form>
What color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue" checked="checked">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Is "Blue" checked by default?</button>
</body>
</html>
<head>
<script>
function displayResult()
{
var x=document.getElementById("blue").defaultChecked;
alert(x);
}
</script>
</head>
<body>
<form>
What color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue" checked="checked">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Is "Blue" checked by default?</button>
</body>
</html>