Input Password disabled attribute

Definition and Usage

disabled Set or return whether the password field should be disabled.

Disabled elements are not available and cannot be clicked. By default, disabled elements are usually displayed in gray in the browser.

This property reflects the HTML disabled attribute.

See also:

HTML Reference Manual:HTML <input> disabled 属性

Example

Example 1

Disable password field:

document.getElementById("myPsw").disabled = true;

Try it yourself

Example 2

Check if the password field is disabled:

var x = document.getElementById("myPsw").disabled;

Try it yourself

Example 3

Enable and disable password field:

function disablePsw() {
  document.getElementById("myPsw").disabled = true;
}
function undisablePsw() {
  document.getElementById("myPsw").disabled = false;
}

Try it yourself

Syntax

Return disabled attribute:

passwordObject.disabled

Set disabled attribute:

passwordObject.disabled = true|false

属性值

描述
true|false

规定是否应禁用密码字段。

  • true - 密码字段被禁用
  • false - 默认。密码字段未禁用

技术细节

返回值: 布尔值,如果密码字段被禁用,则返回 true;否则返回 false

浏览器支持

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 支持 支持 支持 支持