zoukankan      html  css  js  c++  java
  • jQuery---val方法

    val方法

    获取焦点时,判断value等不等于洋酒,true的话就情况,设置为空

        $("#txt").focus(function () {
          //如果是默认值,清空内容
          if($(this).val() === "洋酒"){
            $(this).val("");
          }
        });

    失去焦点时,判断value是否为空,true就添加value值为洋酒

      
        $("#txt").blur(function () {
          //如果为空,就添加value洋酒
          if($(this).val() === ""){
            $(this).val("洋酒");
          }
        });
    <!DOCTYPE html>
    <html lang="zh-CN">
    
    <head>
      <meta charset="UTF-8">
      <title>Title</title>
    
      <style>
        input {
          background-color: rgb(255, 255, 255);
          border: 2px solid rgb(226, 35, 26);
        }
    
        #btn {
          background-color: rgb(225, 37, 27);
           55px;
          height: 30px;
          color: rgb(255, 255, 255);
          font-size: 14px;
        }
    
        #txt {
          color: rgb(152, 152, 152);
           190px;
          height: 25px;
          padding: 5px 10px;
        }
      </style>
    </head>
    
    <body>
      <input type="button" value="搜索" id="btn">
      <input type="text" value="洋酒" id="txt">
    
    
      <script src="jquery-1.12.4.js"></script>
      <script>
        $(function () {
    
          $("#txt").focus(function () {
            //如果是默认值,清空内容
            if ($(this).val() === "洋酒") {
              $(this).val("");
            } s
          });
    
          $("#txt").blur(function () {
            if ("#txt".val === "") {
              $(this).val("洋酒");
            }
          });
        });
      </script>
    </body>
    
    </html>

  • 相关阅读:
    【NOIP2006T】作业调度方案
    「NOIP2012P」寻宝
    51Nod1084 矩阵取数问题 V2
    51Nod1294 修改数组
    51nod1122 机器人走方格V4
    多项式相关模板#1
    51Nod1514 美妙的序列
    Jzoj5674 香槟
    Jzoj5669 排列
    Jzoj5665 奥立卡的诗
  • 原文地址:https://www.cnblogs.com/jane-panyiyun/p/12214259.html
Copyright © 2011-2022 走看看