HTML DOM disabled 属性
JavaScript基础 2022-06-08 15:38:02小码哥的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>
<button id="myButton" onClick="disableButton()">
Click Me!</button>
</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