HTML DOM 输入按钮 type 属性
htmlweb developmentfront end technology更新于 2025/9/18 14:04:17
HTML DOM 输入按钮 type 属性返回输入按钮的类型,即它是"按钮"、"提交"还是"重置"类型。
语法
以下是语法 −
object.type
示例
让我们看一个输入按钮 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>
输出
这将产生以下输出 −

点击“点击我了解我的类型”按钮显示输入按钮的类型。

相关文章
有用资源
html 参考教程 - 该教程包含有关 html 的更多信息:https://www.cainiaomax.com/html/

