密码框失去焦点且为空时显示汉字“密码”、获取焦点时输入内容显示为密码“**********”的实现方法

想要达到的效果:

失去焦点时:

选中输入时时:

通过js动态改变input 的type的属性:

网上已经有相关资料了。这里做一下笔记。原文章地址:http://www.jb51.net/article/43140.htm

<input name=”password” type=”password” id=”password” class=”input” style=”display: none;” />

$(“#showPwd”).focus(function() {
var text_value = $(this).val();
if (text_value == this.defaultValue) {
$(“#showPwd”).hide();
$(“#password”).show().focus();
}
});
$(“#password”).blur(function() {
var text_value = $(this).val();
if (text_value == “”) {
$(“#showPwd”).show();
$(“#password”).hide();
}
});

posted @ 2015-02-27 10:46  goodwell21  阅读(621)  评论(0编辑  收藏  举报