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