如何将HTML输入类型属性从“密码”更改为“文本”? [英] How to change the HTML input type attribute from 'password' to' text'?
本文介绍了如何将HTML输入类型属性从“密码”更改为“文本”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想更改HTML'input'元素'type'属性,从type =password更改为type =text。
I would like to change the HTML 'input' element 'type' attribute, from type="password" to type="text".
我知道通过ID查找元素会更容易,但不是每个页面都有相同的密码输入ID。如何定位密码输入并将其内部值更改为一种文本。
I am aware that it would be easier to find element by ID but not every page has the same id for the password input. How do I target the password inputs and change their inner value to a type of text.
我有几行JavaScript代码:
I have this few lines of JavaScript code:
a=document.getElementsByTagName("input");
a.setAttribute(type,text);
推荐答案
要将密码类型的所有元素转换为文本:
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.
这篇关于如何将HTML输入类型属性从“密码”更改为“文本”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文