| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

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

$("#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);          }      })  });