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