Radio checked 屬性

Radio 對象參考手冊 Radio 對象

定義和用法

checked 屬性可設置或返回某個單選按鈕是否被選中。

語法

設置 checked 屬性:

radioObject.checked=true|false

返回 checked 屬性:

radioObject.checked


流覽器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要流覽器都支持 checked 屬性


實例

實例

下麵的例子可對一個單選按鈕進行選定和不選定:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>IT研修(xuhuhu.com)</title>
<script>
function check(){
    document.getElementById("red").checked=true
}
function uncheck(){
    document.getElementById("red").checked=false
}
</script>
</head>
<body>

<form>
你更喜歡哪種顏色?<br>
<input type="radio" name="colors" id="red">紅色<br>
<input type="radio" name="colors" id="blue">藍色<br>
<input type="radio" name="colors" id="green">綠色
</form>
<button type="button" onclick="check()">選擇 "紅色"</button>
<button type="button" onclick="uncheck()">不選擇 "紅色"</button>
    
</body>
</html>



Radio 對象參考手冊 Radio 對象