HTML DOM Input Password 类型属性
HTML DOM Input 密码类型属性与带有 type=”password”的 input 元素关联。它将始终返回输入密码元素的密码。
语法
以下是密码类型属性的语法 −
passwordObject.type
示例
让我们看一个 Input 密码类型属性示例 −
<!DOCTYPE html>
<html>
<body>
<h1>password type property</h1>
PASSWORD: <input type="password" id="PASS1">
<p>Get the above element type by clicking the below button</p>
<button onclick="getType()">Get Type</button>
<p id="Sample"></p>
<script>
function getType() {
var t = document.getElementById("PASS1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}
</script>
</body>
</html>输出
这将生成以下输出 −

单击“获取类型”按钮 −

在以上示例中 −
我们创建了一个类型为密码的输入字段,其 id 设置为“PASS1”。
PASSWORD: <input type="password" id="PASS1">
然后,我们创建了“获取类型”按钮,当用户单击该按钮时,该按钮将执行 getType() 方法 −
<button onclick="getType()">Get Type</button>
GetType() 方法使用 getElementById() 方法获取输入元素,并将它的类型属性值分配给变量 t。然后,使用 innerHTML 属性在具有 id “Sample”的段落中显示这个变量 −
function getType() {
var t = document.getElementById("PASS1").type;
document.getElementById("Sample").innerHTML = "The type for the input field is : "+t;
}
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP