Input Password maxLength Attribute

Definition and Usage

maxLength Set or return the value of the maxlength attribute of the password field.

The HTML maxlength attribute specifies the maximum number of characters allowed in the password field.

Tip:To set or return the width of the password field (in characters), use size attribute.

See also:

HTML Reference Manual:HTML <input> maxlength 属性

Example

Example 1

Get the maximum number of characters allowed in the specified password field:

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

Try it yourself

Example 2

Set the maximum number of characters allowed in the password field:

document.getElementById("myPsw").maxLength = "10";

Try it yourself

Syntax

Return maxLength attribute:

passwordObject.maxLength

Set maxLength attribute:

passwordObject.maxLength = integer

属性值

描述
integer 规定密码字段中允许的最大字符数。

技术细节

返回值: 数值,表示密码字段中允许的最大字符数。

浏览器支持

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