我使用以下代码在 onclick 和 onfocus 期间更改 HTML 元素的类型。
function ChangeToPassField() {
document.getElementById('password').type="password";
document.getElementById('password').focus();
<input type="text" name="password" id="password" onblur="ChangeToTextField(); if (this.value == '') {this.value = 'Password';}" onclick="ChangeToPassField(); if (this.value == 'Password') { this.value = ''; } else { this.value; }" onfocus="if (this.value == 'Password') { this.value=''; }; this.type='password';" value="Password" style="width:230px; height:25px; margin-left:5px; background:none; border:0px;" />
onclick 和 onfocus 事件在 IE7 和 IE8 中不起作用。它显示如下错误
“无法获取类型属性:不支持此命令”
我该如何解决这个问题?
最佳答案
type
属性 cannot be changed in Internet Explorer (见“备注”部分)。您可以通过将 input
元素替换为新元素来解决此问题。
关于javascript - onclick 和 onfocus 上的 HTML 元素类型更改在 IE 浏览器中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6910561/