Radio typeプロパティ
Radio オブジェクト
定義と使い方
type プロパティは、ラジオボタンのフォーム要素タイプを返します。
ラジオボタンの場合、このプロパティは常に "radio" です。
構文
radioObject.type
ブラウザサポート
![]()
![]()
![]()
![]()
![]()
すべての主要ブラウザは type プロパティをサポートしています。
例
例
次の例では、ラジオボタンのフォーム要素タイプを返します:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("red").type;
alert(x);
}
</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="displayResult()">input タイプを表示</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>サンプル(example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("red").type;
alert(x);
}
</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="displayResult()">input タイプを表示</button>
</body>
</html>
試してみる »
Radio オブジェクト その他の拡張