HTML DOM 文本输入类型属性
HTML DOM 文本输入类型属性返回/设置文本输入的类型。
语法
以下是语法 −
- 返回字符串值
inputTextObject.type
- 将类型设置为字符串值
inputTextObject.type = stringValue
字符串值
这里,“字符串值”可以包括以下内容 −
| 字符串值 | 详细信息 |
|---|---|
| 定义输入类型为电子邮件 | |
| text | 定义输入类型为文本 |
| radio | 定义输入类型为单选按钮 |
| tel | 定义输入类型为电话号码,并显示数字键盘输入 |
示例
我们来看一下文本输入类型属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>Input Text type</title>
<style>
form {
width:70%;
margin: 0 auto;
text-align: center;
}
* {
padding: 2px;
margin:5px;
}
input[type="button"] {
border-radius: 10px;
}
</style>
</head>
<body>
<form>
<fieldset>
<legend>Text-type</legend>
<label for="TextSelect"></label>
<input type="text" id="TextSelect" >
<input type="button" onclick="getTypeOfInput()" value="What to enter?">
</fieldset>
</form>
<script>
var labelSelect = document.querySelector("label");
var inputText = document.getElementById("TextSelect");
function getTypeOfInput() {
labelSelect.innerHTML = ' Plain '+inputText.type+': ';
}
</script>
</body>
</html>输出
将产生以下输出 −
单击“输入什么?”按钮之前 −

单击“输入什么?”按钮之后 −

广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP