คุณสมบัติประเภทปุ่มอินพุต HTML DOM ส่งคืนประเภทของปุ่มอินพุต เช่น ไม่ว่าจะเป็นประเภท "ปุ่ม" "ส่ง" หรือ "รีเซ็ต"
ไวยากรณ์
ต่อไปนี้เป็นไวยากรณ์ -
object.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> ผลลัพธ์
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -

คลิกที่ “คลิกให้ฉันทราบเกี่ยวกับประเภทของฉัน ” เพื่อแสดงประเภทของปุ่มอินพุต
