HTML DOM 單選按鈕型別屬性
Input Checkbox 型別屬性返回/設定 Input Checkbox 的型別。
語法
以下是語法 −
- 返回字串值
inputCheckboxObject.type
- 將 type 設定為字串值
inputCheckboxObject.type = stringValue
字串值
此處,"stringValue" 可以是以下內容 -
| stringValue | 詳情 |
|---|---|
| checkbox | 它定義輸入型別是複選框 |
| radio | 它定義輸入型別是單選按鈕 |
| text | 它定義輸入型別是文字 |
例項
讓我們看一個 Input Checkbox type 屬性的例項 −
<!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>輸出
這將產生以下輸出 −
單擊“更改輸入型別”按鈕之前 −

單擊“更改輸入型別”按鈕之後 −

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP