HTML DOM Input Password 对象

Input Password 对象

Input Password 对象表示带有 type="password" 的 HTML <input> 元素。

访问 Input Password 对象

您可以使用 getElementById() 访问 type="password" 的 <input> 元素:

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

亲自试一试

提示:您还可以通过搜索表单的 elements 集合 来访问 <input type="password">。

创建 Input Password 对象

您可以使用 document.createElement() 方法创建 type="password" 的 <input> 元素:

var x = document.createElement("INPUT");
x.setAttribute("type", "password");

亲自试一试

Input Password 对象属性

属性描述
autocomplete设置或返回密码字段的 autocomplete 属性值。
autofocus设置或返回页面加载时密码字段是否应自动获得焦点。
defaultValue设置或返回密码字段的默认值。
disabled设置或返回是否禁用密码字段。
form返回对包含密码字段的表单的引用。
maxLength设置或返回密码字段的 maxlength 属性值。
name设置或返回密码字段的 name 属性值。
pattern设置或返回密码字段的 pattern 属性值。
placeholder设置或返回密码字段的 placeholder 属性值。
readOnly设置或返回密码字段是否为只读。
required设置或返回在提交表单之前是否必须填写密码字段。
size设置或返回密码字段的 size 属性值。
type返回密码字段是哪种类型的表单元素。
value设置或返回密码字段的 value 属性值。

Input Password 对象方法

方法描述
select()选取密码字段的内容。

标准属性和事件

Input Password 对象同时支持标准属性事件

相关页面

HTML 教程:HTML 表单

HTML 参考手册:HTML <input> 标签

HTML 参考手册:HTML <input> type 属性