HTML DOM Input 按鈕 type 屬性


HTML DOM input 按鈕 type 屬性會得到按鈕 type,即 “button”、“submit” 或 “reset” 型別。

語法

語法如下 −

object.type

示例

我們來看一個 input 按鈕 type 屬性的示例 −

即時演示

<!DOCTYPE html>
<html>
<head>
<title>HTML DOM type Property</title>
<style>
   body{
      text-align:center;
   }
   .btn{
      display:block;
      margin:1rem auto;
      background-color:#db133a;
      color:#fff;
      border:1px solid #db133a;
      padding:0.5rem;
      border-radius:50px;
      width:40%;
   }
   .show-type{
      font-weight:bold;
      font-size:1.4rem;
      color:#ffc107;
   }
</style>
</head>
<body>
<h1>type Property Example</h1>
<input type = "submit" onclick = "getType()" class = "btn" value = "Click me to know about my type">
<div class="show-type"></div>
<script>
   function getType() {
      var btnType = document.querySelector(".btn").type;
      document.querySelector(".show-type").innerHTML = btnType;
   }
</script>
</body>
</html>

結果

會產生以下結果 −

點選“點選此處瞭解我的型別”按鈕,可以顯示 input 按鈕的型別。

更新於: 30-Jul-2019

131 瀏覽

開啟你的 職業生涯

透過完成該課程獲得認證

開始
廣告
© . All rights reserved.