คุณสมบัติ typeของ hidden input คืนค่าสตริง "hidden" เสมอ ใช้ยืนยันประเภทของอิลิเมนต์
รูปแบบ (Syntax)
object.type
ตัวอย่างการใช้งาน
แสดงค่า type ของ hidden input:
<!DOCTYPE html>
<html>
<head>
<style>
body { text-align: center; background-color: #F19A3E; color: #fff; }
.btn { background-color: #3C787E; border: none; height: 2rem; border-radius: 50px; width: 60%; margin: 1rem auto; display: block; color: #fff; outline: none; }
.show { color: #fff; font-size: 1.2rem; font-weight: 600; }
</style>
</head>
<body>
<h1>ตัวอย่าง Hidden type Property</h1>
ใส่ชื่อของคุณ: <input type="hidden" class="input-field">
<button onclick="getType()" class="btn">คลิกเพื่อดู type ของ input</button>
<div class="show"></div>
<script>
function getType() {
var inputField = document.querySelector(".input-field");
var msgDiv = document.querySelector(".show");
msgDiv.innerHTML = "type = " + inputField.type;
}
</script>
</body>
</html>
คำแนะนำ
คุณสมบัติ type เป็นแบบอ่านอย่างเดียว (read-only) ไม่สามารถเปลี่ยนแปลงได้หลังสร้างอิลิเมนต์แล้ว