Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính type của Input Hidden trong HTML DOM

Thuộc tính type của <input type="hidden"> luôn trả về chuỗi "hidden". Thuộc tính này **chỉ đọc**.

Cú pháp

hiddenInput.type

Ví dụ: Kiểm tra type của hidden input

<!DOCTYPE html>
<html>
<head>
    <style>
        body { text-align: center; background: #F19A3E; color: white; font-family: sans-serif; padding: 20px; }
        .btn {
            background-color: #3C787E; border: none; color: white;
            padding: 10px 20px; border-radius: 25px; width: 60%;
            margin: 15px auto; display: block; cursor: pointer;
        }
        .show { color: white; font-size: 1.2rem; font-weight: 600; margin-top: 15px; }
    </style>
</head>
<body>
    <h1>Demo Hidden type Property</h1>
    

Nhập tên (ẩn): <input type="hidden" class="input-field">

<button onclick="getType()" class="btn">Lấy type của input trên</button> <div id="result" class="show"></div> <script> function getType() { var input = document.querySelector(".input-field"); document.getElementById("result").textContent = "type = " + input.type; } </script> </body> </html>

Kết quả

Trước khi nhấn:

Thuộc tính type của Input Hidden trong HTML DOM

Sau khi nhấn nút:

Thuộc tính type của Input Hidden trong HTML DOM

ℹ️ Lưu ý: Luôn trả về "hidden". Dùng để kiểm tra loại input trong code xử lý form động (VD: lọc bỏ hidden fields khi serialize form).