IE8密码字段显示输入的值,而不是显示星号


IE8 Password field showing entered value instead of showing asterisks

在我的网站中,密码字段显示输入的值,而不是显示星号符号。这适用于所有其他浏览器。IE1、IE2、IE3、IE4、IE7和IE9也同样工作。只是在IE8中我没有得到它。任何帮助都将不胜感激。

对于参考:只需检查网站并点击登录,就会出现登录框,您可以使用该密码字段检查问题。

<input type="password" name="password" id="password" value="Password" 
onblur="if(this.value == '') { this.style.color='#bbb'; this.value='Password'; this.type='text'} 
else {this.type='password';}" 
onfocus="if (this.value == 'Password') {this.style.color='#000'; this.value=''; this.type='password'} else {this.type='password';}" style="color: rgb(0, 0, 0);">

我猜这里是因为我不想浏览您的所有代码,但我想当用户关注input时,您将用<input type="password" />替换<input type="text" />。我不认为这是最好的跨浏览器解决方案。

如果你想支持旧的浏览器,你需要使用javascript解决方案,因为HTML5placeholder值不适用于所有浏览器。

一个好的解决方案是使用位于input下的<label>标签,而不是伪造它。有关好的示例,请参阅:http://blog.stannard.net.au/2011/01/07/creating-a-form-with-labels-inside-text-fields-using-jquery/

此解决方案的优点包括跨浏览器兼容性、可访问性和语义标记。