Computer >> Máy Tính >  >> Lập trình >> HTML

HTML DOM Input Thuộc tính loại ẩn

Thuộc tính kiểu ẩn đầu vào HTML DOM trả về giá trị của thuộc tính kiểu của trường đầu vào.

Cú pháp

Sau đây là cú pháp -

object.type

Ví dụ

Hãy để chúng tôi xem một ví dụ về thuộc tính loại ẩn đầu vào HTML DOM -

<!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>DOM Hidden type Property Demo</h1>
Enter your Name:<input type="hidden" class="input-field">
<button onclick="getType()" class="btn">Click to get above input type</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>

Đầu ra

Điều này sẽ tạo ra kết quả sau -

HTML DOM Input Thuộc tính loại ẩn

Nhấp vào nút “Nhấp để nhận loại đầu vào phía trên” để nhận giá trị của thuộc tính loại của trường nhập ẩn.

HTML DOM Input Thuộc tính loại ẩn