HTML DOM 輸入隱藏型別屬性


HTML DOM input hidden type 屬性會返回 input 欄位的 type 屬性的值。

句法

以下是語法 −

object.type

示例

讓我們看一個 HTML DOM input hidden type 屬性的示例 −

 實際演示

<!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>

輸出

這將產生以下輸出 −

點選“單擊以獲取上述輸入型別”按鈕以獲取 hidden 輸入欄位的 type 屬性的值。

更新於:09-05-2023

359 次瀏覽

開啟你的 職業

透過完成課程來獲得認證

開始
廣告
© . All rights reserved.