我使用 jQuery 而不是 HTML5 占位符属性
<input type="text" name="email" value="Email" onfocus="if (this.value == 'Email') { this.value = ''; }" onblur="if (this.value == '') { this.value = 'Email'; }" onclick="if (this.value == 'Email') { this.value = ''; }" />
这对于type="text"
但对于type="password"
它只显示*
我将如何使用密码字段的占位符?需要在IE8下
提前感谢各位的解答...
我创建了一个正常的输入,然后focus
将其切换为密码字段,如果该值为空blur
,然后将其切换回正常输入,否则将其保留为密码字段。
这是一个工作中的 JSFiddle: http://jsfiddle.net/q8ajJ/ http://jsfiddle.net/q8ajJ/ http://jsfiddle.net/q8ajJ/
The HTML
<!-- Style = display none for people who dont have javascript -->
<input type="text" name="fake_pass" id="fake_pass" value="Enter Password:" style="display:none"/>
<input type="password" name="real_pass" id="real_pass"/>
JavaScript (jQuery)
// On DOM ready, hide the real password
$('#real_pass').hide();
// Show the fake pass (because JS is enabled)
$('#fake_pass').show();
// On focus of the fake password field
$('#fake_pass').focus(function(){
$(this).hide(); // hide the fake password input text
$('#real_pass').show().focus(); // and show the real password input password
});
// On blur of the real pass
$('#real_pass').blur(function(){
if($(this).val() == ""){ // if the value is empty,
$(this).hide(); // hide the real password field
$('#fake_pass').show(); // show the fake password
}
// otherwise, a password has been entered,
// so do nothing (leave the real password showing)
});
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)