Input Password size attribute

Definition and Usage

size Set or return the size attribute of the password field.

The HTML size attribute specifies the width of the password field (in number of characters).

The default value is 20.

Tip:To set or return the maximum number of allowed characters in the password field, use maxLength attribute.

See also:

HTML Reference Manual:HTML <input> size 属性

Example

Example 1

Change the width of the password field:

document.getElementById("myPsw").size = "50";

Try it yourself

Example 2

Get the width of the password field:

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

Try it yourself

Syntax

Return size attribute:

passwordObject.size

Set size attribute:

passwordObject.size = number

属性值

描述
number 规定密码字段的宽度,以字符为单位。默认值为 20。

技术细节

返回值: 数值,表示密码字段的宽度,以字符为单位。

浏览器支持

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