Button disabled attribute
Definition and usage
disabled
Attribute sets or returns whether the button is disabled.
Disabled elements are not available and cannot be clicked. By default, disabled elements are usually displayed in gray in the browser.
This attribute reflects HTML disabled attribute.
Example
Example 1
Disable button:
document.getElementById("myBtn").disabled = true;
Example 2
Check if the button is disabled:
var x = document.getElementById("myBtn").disabled;
Example 3
Disable and enable button:
function disableBtn() { document.getElementById("myBtn").disabled = true; } function enableBtn() { document.getElementById("myBtn").disabled = false; }
Syntax
Return disabled attribute:
buttonObject.disabled
set disabled attribute:
buttonObject.disabled = true|false
属性值
值 | 描述 |
---|---|
true|false |
规定是否应禁用按钮。
|
技术细节
返回值: | 布尔值,如果按钮被禁用则返回 true,否则返回 false。 |
---|
浏览器支持
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
支持 | 支持 | 支持 | 支持 | 支持 |
相关页面
HTML 参考手册:HTML <button> disabled অপারেশন