HTML DOM 输入按钮 disabled 属性
htmlweb developmentfront end technology更新于 2025/6/18 21:32:17
HTML DOM 输入按钮 disabled 属性返回并修改 HTML 中输入按钮 disabled 属性的值。
语法
以下是语法 −
1. 返回名称
object.disabled
2. 修改名称
object.disabled = true|false
示例
让我们看一个 disabled 属性的示例 −
<!DOCTYPE html>
<html>
<head>
<title>HTML DOM disabled 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:80%;
}
.show-message{
font-weight:bold;
font-size:1.4rem;
color:#ffc107;
}
</style>
</head>
<body>
<h1>disabled Property Example</h1>
<input type="button" onclick="disableMe()" class="btn" value="Click me to Disable me">
<div class="show-message"></div>
<script>
function disableMe() {
var btn= document.querySelector(".btn");
btn.disabled = true;
document.querySelector(".show-message").innerHTML="Previously I'm enabled but now I'm disabled";
}
</script>
</body>
</html>
输出
这将产生以下输出 −
现在,点击“点击我以禁用我”按钮以禁用红色按钮。

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

