jquery 失去焦点时输入框为空时自动填写默认内容

 1 $("#address").focus(function () { // 地址框获得鼠标焦点
 2     var txt_value = $(this).val(); // 得到当前文本框的值
 3     if (txt_value == "请输入邮箱地址") {
 4         $(this).val(""); // 如果符合条件,则清空文本框内容
 5     }
 6 });
 7 $("#address").blur(function () { // 地址框失去鼠标焦点
 8     var txt_value = $(this).val(); // 得到当前文本框的值
 9     if (txt_value == "") {
10         $(this).val("请输入邮箱地址"); // 如果符合条件,则设置内容
11     }
12 })
13  
14 $("#password").focus(function () {
15     var txt_value = $(this).val();
16     if (txt_value == "请输入邮箱密码") {
17         $(this).val("");
18     }
19 });
20 $("#password").blur(function () {
21     var txt_value = $(this).val();
22     if (txt_value == "") {
23         $(this).val("请输入邮箱密码");
24     }
25 })
26  
27  
28  
29  
30 //另一个方法
31  
32 $(function () {
33     $("#address").focus(function () { // 地址框获得鼠标焦点
34         var txt_value = $(this).val(); // 得到当前文本框的值
35         if (txt_value == this.defaultValue) {
36             $(this).val(""); // 如果符合条件,则清空文本框内容
37         }
38     });
39     $("#address").blur(function () { // 地址框失去鼠标焦点
40         var txt_value = $(this).val(); // 得到当前文本框的值
41         if (txt_value == "") {
42             $(this).val(this.defaultValue); // 如果符合条件,则设置内容
43         }
44     })
45      
46     $("#password").focus(function () {
47         var txt_value = $(this).val();
48         if (txt_value == this.defaultValue) {
49             $(this).val("");
50         }
51     });
52     $("#password").blur(function () {
53         var txt_value = $(this).val();
54         if (txt_value == "") {
55             $(this).val(this.defaultValue);
56         }
57     })
58 });

 

转载于:https://www.cnblogs.com/chengkun101/p/5228577.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值