HTMLDOM入力チェックボックスタイププロパティ
入力チェックボックスタイププロパティは、入力チェックボックスのタイプを返す/設定します。
構文
以下は構文です-
- 文字列値を返す
inputCheckboxObject.type
- タイプの設定 文字列値へ
inputCheckboxObject.type = stringValue
文字列値
ここで、「stringValue」は次のようになります-
| stringValue | 詳細 th> |
|---|---|
| チェックボックス | 入力タイプがチェックボックスであることを定義します |
| ラジオ | 入力タイプが無線であることを定義します |
| テキスト | 入力タイプがテキストであることを定義します |
例
入力チェックボックスタイプの例を見てみましょう プロパティ-
<!DOCTYPE html>
<html>
<head>
<title>Type Attribute of Checkbox</title>
</head>
<body>
<form id="Form">
<div>
Other: <input id="formCheckbox" type="checkbox" name="formCheckbox">
</div>
</form>
<button onclick="changeType()">Change type of input</button>
<div id="displayDiv"></div>
<script>
var typeOfInput = document.getElementById("formCheckbox");
var displayDiv = document.getElementById("displayDiv");
displayDiv.textContent = 'Type of Input: ' + typeOfInput.type function changeType(){
if(typeOfInput.type == 'checkbox'){
typeOfInput.type = 'text' displayDiv.textContent = 'Type of Input: ' + typeOfInput.type
}
}
</script>
</body>
</html> 出力
これにより、次の出力が生成されます-
[入力の種類を変更]ボタンをクリックする前に-
[入力の種類を変更]ボタンをクリックした後-
-
HTMLDOM入力番号タイププロパティ
HTML DOM入力番号typeプロパティは、type =” number”を持つinput要素に関連付けられています。入力された数値要素の数値を常に返します。 構文 以下は、数値タイププロパティの構文です- numberObject.type 例 HTMLDOM入力番号タイププロパティの例を見てみましょう- <!DOCTYPE html> <html> <body> <h1>Input Number type property</h1> PHONE NO: <input type="number" id
-
HTMLDOM入力リセットタイププロパティ
HTML DOM入力リセットタイププロパティは、type =” reset”を持つ入力要素に関連付けられています。入力リセット要素に対しては常にリセットを返します。 構文 以下は、リセットタイププロパティの構文です- resetObject.type 例 リセットタイププロパティの例を見てみましょう- <!DOCTYPE html> <html> <body> <h1>Input reset type Property</h1> <form style="border:solid 2px green;padding