下面的代码适用于所有网络浏览器,除了IE
:
<input type="text" name="passwordLogin" value="Password" onfocus="if(this.value=='Password'){this.value=''; this.type='password'};" onblur="if(this.value==''){this.value='Password'; this.type='text'};" size="25" />
我如何为 IE 修复它?
我做了一些更改,但它仍然有错误。
我希望它像这样工作:
<input type="text" name="usernameLogin" value="Email" onfocus="if(this.value=='Email'){this.value=''};" onblur="if(this.value==''){this.value='Email'};" size="25" />
如果我不输入任何内容,它会将值放回原处。
所以我试过这个:
<td colspan="2" id="passwordLoginTd">
<input id="passwordLoginInput1" type="text" name="passwordLogin" value="Password" onfocus="passwordFocus()" size="25" />
<input id="passwordLoginInput2" style="display: none;" type="password" name="passwordLogin" value="" onblur="passwordBlur()" size="25" />
</td>
<script type="text/javascript">
//<![CDATA[
passwordElement1 = document.getElementById('passwordLoginInput1');
passwordElement2 = document.getElementById('passwordLoginInput2');
function passwordFocus() {
passwordElement1.style.display = "none";
passwordElement2.style.display = "inline";
passwordElement2.focus();
}
function passwordBlur() {
if(passwordElement2.value=='') {
passwordElement2.style.display = "none";
passwordElement1.style.display = "inline";
passwordElement1.focus();
}
}
//]]>
</script>
如您所见,模糊不起作用。
最后我明白了,我需要删除:
passwordElement1.focus();