且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将HTML输入类型属性从“密码”更改为“文本”?

更新时间:2023-10-14 23:44:46

要将密码类型的所有元素转换为文本:

To convert all elements of type password to text:

var arr = document.getElementsByTagName("input");
for (var i = 0; i < arr.length; i++) {
    if (arr[i].type == 'password') arr[i].setAttribute('type','text');
}

注意:并非所有浏览器都允许动态更改在输入上键入属性。

Note: Not all browsers allow dynamic changes to the type attribute on inputs.