HTML DOM disabled 属性
JavaScript基础 2022-06-08 16:00:00小码哥的IT人生shichen
HTML DOM disabled 属性
定义和用法
disabled 属性可设置或返回是否禁用按钮。
语法
buttonObject.disabled=true|false
实例
下面的例子可在点击按钮时禁用该按钮:
<html>
<head>
<script type="text/javascript">
function disableButton()
{
document.getElementById("myButton").disabled=true
}
</script>
</head>
<body>
<form>
<input type="button" id="myButton"
value="Click me!" onclick="disableButton()" />
</form>
</body>
</html>
TIY
完整实例【提示按钮的 id、类型和值 + 禁用按钮】:
<!doctype html>
<html>
<head>
</head>
<script type="text/javascript">
function alertId()
{
var txt = "Id:" + document.getElementById("myButton").id;
txt = txt + ", type:" + document.getElementById("myButton").type;
alert(txt)
document.getElementById("myButton").disabled = true;
}
</script>
<body>
<form>
<button id="myButton" onClick="alertId()">
Click me!</button>
</form>
</body>
</html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html