คุณสมบัติ type ของ input type="password" เกี่ยวข้องกับแอตทริบิวต์ type คุณสมบัตินี้เป็น read-only และจะคืนค่า "password" เสมอสำหรับ password input element
ไวยากรณ์ (Syntax)
passwordObject.type
ตัวอย่างการใช้งาน
<!DOCTYPE html>
<html>
<body>
<h1>คุณสมบัติ type ของ Password</h1>
รหัสผ่าน: <input type="password" id="PASS1">
<p>คลิกปุ่มเพื่อดู type ของ input element</p>
<button onclick="getType()">ดู Type</button>
<p id="Sample"></p>
<script>
function getType() {
var t = document.getElementById("PASS1").type;
document.getElementById("Sample").innerHTML = "Type ของ input field คือ: " + t;
}
</script>
</body>
</html>
ผลลัพธ์
เริ่มต้น: ช่องกรอกรหัสผ่าน id="PASS1"
คลิก "ดู Type": แสดง "Type ของ input field คือ: password"
คำอธิบายโค้ด
- Input field:
type="password",id="PASS1" - ปุ่ม "ดู Type" เรียก
getType() - ดึง
.typeproperty คืนค่า "password"
การใช้งาน: เหมือนกับ radio type — ใช้ตรวจสอบประเภท input element แบบไดนามิกใน JavaScript