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 按鈕的型別。

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP