HTML DOM Input Text type 属性
htmlweb developmentfront end technology更新于 2025/8/2 21:32:17
HTML DOM Input Text type 属性返回/设置输入文本的类型。
语法
以下是语法 −
- 返回字符串值
inputTextObject.type
- 将类型设置为字符串值
inputTextObject.type = stringValue
字符串值
此处,"stringValue" 可以是以下 −
| stringValue | 详细信息 |
|---|---|
| 它定义了输入类型为 email | |
| text | 它定义了输入类型为 text |
| radio | 它定义了输入类型为 radio |
| tel | 它定义了输入类型为 tel,并且显示数字键盘用于输入 |
示例
让我们看一个 Input Text type 属性的示例 −
<!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>
输出
这将产生以下输出 −
点击"输入什么?"按钮之前 −

点击"输入什么?"按钮之后 −

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

