jquery 失去焦点时输入框为空时自动填写默认内容
2018-07-20 来源:open-open
$("#address").focus(function () { // 地址框获得鼠标焦点
var txt_value = $(this).val(); // 得到当前文本框的值
if (txt_value == "请输入邮箱地址") {
$(this).val(""); // 如果符合条件,则清空文本框内容
}
});
$("#address").blur(function () { // 地址框失去鼠标焦点
var txt_value = $(this).val(); // 得到当前文本框的值
if (txt_value == "") {
$(this).val("请输入邮箱地址"); // 如果符合条件,则设置内容
}
})
$("#password").focus(function () {
var txt_value = $(this).val();
if (txt_value == "请输入邮箱密码") {
$(this).val("");
}
});
$("#password").blur(function () {
var txt_value = $(this).val();
if (txt_value == "") {
$(this).val("请输入邮箱密码");
}
})
//另一个方法
$(function () {
$("#address").focus(function () { // 地址框获得鼠标焦点
var txt_value = $(this).val(); // 得到当前文本框的值
if (txt_value == this.defaultValue) {
$(this).val(""); // 如果符合条件,则清空文本框内容
}
});
$("#address").blur(function () { // 地址框失去鼠标焦点
var txt_value = $(this).val(); // 得到当前文本框的值
if (txt_value == "") {
$(this).val(this.defaultValue); // 如果符合条件,则设置内容
}
})
$("#password").focus(function () {
var txt_value = $(this).val();
if (txt_value == this.defaultValue) {
$(this).val("");
}
});
$("#password").blur(function () {
var txt_value = $(this).val();
if (txt_value == "") {
$(this).val(this.defaultValue);
}
})
});
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇: Android剪裁图片简单的方法
最新资讯
热门推荐