我有用户名和密码文本框。我希望它们都显示默认文本,即“用户名”和“密码”,但是当用户单击密码框时,出于安全原因,它应该动态更改为“密码”类型。
我已经设法使用 JavaScript 代码轻松地完成此操作,但它不想在 IE 中工作。
<input id="username" class="username" name="u" type="text" value="username" onclick="if(this.value='username') {this.value=''};" />
<input id="password" class="password" name="p" type="text" value="password" onclick="if(this.value='password') {this.value=''; this.type='password'};" />
最佳答案
假设你的 html 代码是这样的
<input type="text" id="txtId" />
你可以使用Jquery替换它,
$('#txtId').replaceWith('<input type="password" id="txtId" />')
关于javascript - 以编程方式将文本框类型从类型 ='text' 更改为类型 ='password',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5878636/