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