Radio defaultChecked 屬性
Radio 對(duì)象定義和用法
defaultChecked 屬性可返回 checked 屬性的默認(rèn)值。
如果單選按鈕的默認(rèn)狀態(tài)是選中,則返回 true,否則返回 fasle。
語(yǔ)法
radioObject.defaultChecked
瀏覽器支持
所有主要瀏覽器都支持 defaultChecked 屬性
實(shí)例
實(shí)例
檢測(cè) "Blue" 選項(xiàng)是否默認(rèn)選中:
<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>
嘗試一下 ?
Radio 對(duì)象
更多建議: