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 });
  • 相关阅读:
    P4365 [九省联考2018]秘密袭击coat
    P3705 [SDOI2017]新生舞会 01分数规划+费用流
    P4313 文理分科 最小割
    P1707 刷题比赛
    P3994 高速公路 树形DP+斜率优化+二分
    P3384 【模板】树链剖分
    P4915 帕秋莉的魔导书
    P3690 【模板】Link Cut Tree (动态树)
    P3615 如厕计划
    loj #2538. 「PKUWC2018」Slay the Spire
  • 原文地址:https://www.cnblogs.com/chengkun101/p/5228577.html
Copyright © 2011-2022 走看看