Radio checkedプロパティ
Radio オブジェクト
定義と用法
checked プロパティは、ラジオボタンが選択されているかどうかを設定または返します。
構文
checked プロパティを設定する:
radioObject.checked=true|false
checked プロパティを返す:
radioObject.checked
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザが checked プロパティをサポートしています。
例
例
次の例では、ラジオボタンを選択または選択解除できます:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.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>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.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 オブジェクト その他の拡張