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 });
  • 相关阅读:
    @transactional注解下失效
    string.format格式化字符串中转义大括号“{}”
    ArrayList循环遍历并删除元素的常见陷阱
    HashMap、HashTable与ConcurrentHashMap区别
    -webkit-,-moz-,-ms-,-o-具体指什么了?
    常用js正则表达式大全
    hashcode详解
    如何区分oracle服务器、oracle客户端、plsql?
    Oracle Client(客户端) 安装与配置
    Openresty使用
  • 原文地址:https://www.cnblogs.com/chengkun101/p/5228577.html
Copyright © 2011-2022 走看看