小码哥的IT人生

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

版权所有 © 小码哥的IT人生
Copyright © phpcodeweb All Rights Reserved
ICP备案号:苏ICP备17019232号-2  

苏公网安备 32030202000762号

© 2021-2024