HTML DOM Input Reset type 屬性


HTML DOM Input Reset type 屬性與具有 type=”reset”屬性的 input 元素相關聯。它總是會為 input reset 元素返回 reset。

語法

以下是 reset type 屬性的語法 −

resetObject.type

示例

讓我們看一個 reset type 屬性的示例 −

<!DOCTYPE html>
<html>
<body>
<h1>Input reset type Property</h1>
<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>
<p>Get the above input element type by clicking the below button</p>
<button type="button" onclick="resetType()">GET Type</button>
<p id="Sample"></p>
<script>
   function resetType() {
      var P=document.getElementById("RESET1").type;
      document.getElementById("Sample").innerHTML = "The type for the input field is: "+P ;
   }
</script>
</body>
</html>

輸出

這將產生以下輸出 −

單擊獲取型別屬性 −

在上面的示例中 −

我們建立了一個具有 type=”reset”,id=”RESET1”屬性的 <input> 元素。單擊此按鈕將重置表單資料。此按鈕位於一個包含兩個文字欄位且應用了內聯樣式的表單中 −

<form style="border:solid 2px green;padding:2px">
UserName: <input type="text" id="USR"> <br>
Location: <input type="text" id="Age"> <br><br>
<input type="reset" id="RESET1">
</form>

然後我們建立了一個按鈕“GET Type”,當用戶單擊該按鈕時,它將執行 resetType() 方法 −

<button type="button" onclick="resetType()">GET Type</button>

resetType() 方法使用 getElementById() 方法獲取輸入元素,並將它的型別屬性值指定給變數 P。然後使用其 innerHTML 特性在 ID 為 “Sample” 的段落中顯示此變數 −

function getType() {
   var P = document.getElementById("RESET1").type;
   document.getElementById("Sample").innerHTML = "The type for the input field is : "+P;
}

更新時間:2019 年 8 月 19 日

116 次瀏覽

開啟你的 職業生涯

完成課程即可獲得認證

開始學習
廣告