Radio checked 屬性


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

語法
設置 checked 屬性:

radioObject.checked=true|false
返回 checked 屬性:

radioObject.checked


瀏覽器支持
Internet ExplorerFirefoxOperaGoogle ChromeSafari

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

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鳥教程(runoob.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>
 

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM