jQuery输入占位符类型密码在IE8 [英] jQuery input placeholder for type password in IE8
本文介绍了jQuery输入占位符类型密码在IE8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用jQuery代替HTML5 placeholder属性
I am using jQuery instead of HTML5 placeholder attribute
<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
但
this is working fine for type="text"
but for type="password"
it show only *
我将如何使用占位符作为密码字段?需要在IE8中
How i will use placeholder for password field? Need out in IE8
预先感谢您的回答...
Advance thanks for answers...
推荐答案
我创建一个正常的输入,并在 focus
切换到一个密码字段,如果该值在 blur为空
,然后将其切换回正常输入,否则将其保留为密码字段。
I create a normal input, and on focus
switch it to a password field, and if the value is empty on blur
, then switch it back to a normal input, else leave it as the password field.
这是一个工作的JSFiddle: http://jsfiddle.net/q8ajJ/
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)
});
这篇关于jQuery输入占位符类型密码在IE8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文