Radio defaultChecked 屬性

定義和用法
defaultChecked 屬性可返回 checked 屬性的默認值。
如果單選按鈕的默認狀態(tài)是選中,則返回 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>
嘗試一下 ?

更多建議: