zoukankan      html  css  js  c++  java
  • 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 });
  • 相关阅读:
    用Service充当Domain Object
    Scrum方法回顾
    为什么使用User Story Map
    前端状态管理之状态机
    项目进度管理注意事项
    单元测试遇到的最难的问题
    JS AMD模块的循环依赖
    jupyter notebook常用快捷键
    Jupyter-NoteBook-你应该知道的N个小技巧
    Python之配置日志的几种方式(logging模块)
  • 原文地址:https://www.cnblogs.com/chengkun101/p/5228577.html
Copyright © 2011-2022 走看看