下面是编程之家 jb51.cc 通过网络收集整理的代码片段。
编程之家小编现在分享给大家,也给大家做个参考。
$("#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); } }) });
以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。