admin管理员组文章数量:1430625
I want creating form field hints where the default value shows 'Password' and on focus, it goes away. If the field loses focus with no use input, it will reveal back to the default value of 'Password'.
Problem: The default value for the password field gets masked as well. How can I show the default value of 'Password' without getting masked, and masks only the user input?
jQuery Code
$(".splash_register_short_input, .splash_register_long_input").each(function() {
$(this).val( $(this).attr('title') );
});
$(".splash_register_short_input, .splash_register_long_input").focus(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val('');
}
});
$(".splash_register_short_input, .splash_register_long_input").blur(function() {
if($(this).val() == '') { // If there is no user input
$(this).val($(this).attr('title'));
$(this).removeClass('splash_register_have_userinput');
} else { // If there is user input
$(this).addClass('splash_register_have_userinput');
}
});
HTML Code
<form id="splash_register_traditional_form">
<input type="text" name="register_first_name" class="splash_register_short_input" title="First Name" /><label for="register_first_name"></label>
<input type="text" name="register_last_name" class="splash_register_short_input" title="Last Name" /><label for="register_last_name"></label>
<input type="text" name="register_email" class="splash_register_long_input" title="Email" /><label for="register_email"></label>
<input type="password" name="register_password" class="splash_register_long_input" title="Password" /><label for="register_password"></label>
<input type="submit" id="splash_register_signup_button" value="Sign up" />
</form>
I want creating form field hints where the default value shows 'Password' and on focus, it goes away. If the field loses focus with no use input, it will reveal back to the default value of 'Password'.
Problem: The default value for the password field gets masked as well. How can I show the default value of 'Password' without getting masked, and masks only the user input?
jQuery Code
$(".splash_register_short_input, .splash_register_long_input").each(function() {
$(this).val( $(this).attr('title') );
});
$(".splash_register_short_input, .splash_register_long_input").focus(function() {
if($(this).val() == $(this).attr('title')) {
$(this).val('');
}
});
$(".splash_register_short_input, .splash_register_long_input").blur(function() {
if($(this).val() == '') { // If there is no user input
$(this).val($(this).attr('title'));
$(this).removeClass('splash_register_have_userinput');
} else { // If there is user input
$(this).addClass('splash_register_have_userinput');
}
});
HTML Code
<form id="splash_register_traditional_form">
<input type="text" name="register_first_name" class="splash_register_short_input" title="First Name" /><label for="register_first_name"></label>
<input type="text" name="register_last_name" class="splash_register_short_input" title="Last Name" /><label for="register_last_name"></label>
<input type="text" name="register_email" class="splash_register_long_input" title="Email" /><label for="register_email"></label>
<input type="password" name="register_password" class="splash_register_long_input" title="Password" /><label for="register_password"></label>
<input type="submit" id="splash_register_signup_button" value="Sign up" />
</form>
Share
Improve this question
asked Nov 11, 2011 at 18:21
NyxynyxNyxynyx
63.9k163 gold badges507 silver badges856 bronze badges
3 Answers
Reset to default 5You can simply use the HTML5 placeholder
-attribute:
<input type="password" placeholder="Enter Password..." />
Concerning the lack of backwards patibility as mentioned in the ments, this jQuery placeholder plugin bined with some kind of a fallback machanism in case the attribute is not supported (like maybe this one) may be helpful.
Best way to do it would be to not set default value as value of password field but as an overlay over password field which disappears on focus or when user changes value to something else. You can use the arelady existing jquery in-field-label plugins e.g.
http://www.viget./inspire/a-better-jquery-in-field-label-plugin/
http://fuelyourcoding./scripts/infield/
http://www.kryogenix/code/browser/labelify/
To hide password programatically add this line below oncreate android.provider.Settings.System.putInt(this.getContentResolver(),android.provider.Settings.System.TEXT_SHOW_PASSWORD, 0);
本文标签: javascriptDisable password masking in password fieldStack Overflow
版权声明:本文标题:javascript - Disable password masking in password field - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745523113a2661717.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论