HTML DOM 輸入密碼錶單屬性
HTML DOM 輸入密碼錶單屬性用於返回包含輸入密碼欄位的表單引用。如果輸入密碼欄位不在表單中,則它將返回 NULL。此屬性是隻讀的。
語法
以下是輸入密碼錶單屬性的語法。
passwordObject.form
示例
讓我們看一個輸入密碼錶單屬性的示例 -
<!DOCTYPE html>
<html>
<body>
<h1>Input Password form Property</h1>
<form id="NEW_FORM">
Password: <input type="password" id="PASS">
</form>
<p>Get the form id by clicking on the below button</p>
<button type="button" onclick="formId()">GET FORM</button>
<p id="Sample"></p>
<script>
function formId() {
var P=document.getElementById("PASS").form.id;
document.getElementById("Sample").innerHTML = "The id of the form containing the password field is: "+P ;
}
</script>
</body>
</html>輸出
將生成以下輸出 -

單擊“獲取表單”按鈕 -

在上面的示例中 -
我們首先使用 id 為“PASS”建立了一個輸入密碼欄位,並將其包含在 id 為“NEW_FORM”的 <form> 元素中 -
<form id=”NEW_FORM”> Password: <input type="password" id="PASS"> </form>
然後建立了一個按鈕“獲取表單”,它將在使用者單擊時執行 formId() 方法 -
<button type="button" onclick="formId()">GET FORM</button>
formId() 方法使用 getElementById() 方法獲取具有密碼型別的輸入欄位,並獲取包含密碼欄位的表單物件的 id 屬性。然後將其值分配給變數 P,並使用其 innerHTML 屬性顯示在 id 為“樣本”的段落中 -
function formId() {
var P=document.getElementById("PASS").form.id;
document.getElementById("Sample").innerHTML = "The id of the form containing the password field is: "+P ;
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP