zoukankan      html  css  js  c++  java
  • js文本框聚焦边框变色

    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <style type="text/css">
    .fun {
     margin: 0 auto;
      1000px;
     overflow: hidden;
     box-shadow: 0 3px 6px rgba(0, 0, 0, 0.1);
     border: solid 1px #ccc;
     font-family: Microsoft YaHei;
     overflow: hidden;
    }

    .inputText {
     border: solid 1px #ccc;
     height: 40px;
      200px;
     line-height: 40px/9;
     padding: 0 2px;
     box-shadow: inset 0 0 4px rgba(0, 0, 0, 0.1);
     margin: 10px 0;
     outline: none;
     font-family: arial;
     font-weight: 700;
     text-indent: 5px;
     color: #1C1C1C;
     display: inline-block;
    }

    .inputFocus {
     border: solid 1px #1398FF;
     box-shadow: 0 0 5px rgba(0, 192, 255, 0.4);
    }

    .text {
     padding: 15px 0 15px 75px;
    }

    h1 {
     text-align: center;
     padding: 10px 0;
     margin: 0;
     background: -webkit-linear-gradient(#fcfcfc, #f9f9f9) repeat;
     background: -moz-linear-gradient(#fcfcfc, #f9f9f9) repeat;
     border-bottom: solid 1px #ccc;
     font-weight: 400;
     text-shadow: 1px 1px 3px #fff;
    }
    </style>

    <script src="resources/js/jquery-1.7.1.min.js" type="text/javascript"></script>
    <script type="text/javascript">
     // JavaScript Document
     $(document).ready(function() {
      function input() {
       //each遍历文本框
       $(".inputText").each(function() {
        // 保存当前文本框的值
        var $val = this.value;
        $(this).focus(function() {
         // 获得焦点时,如果值为默认值,则清空文本框的值
         if (this.value == $val) {
          this.value = "";
          // alert(this.className);
          this.className = "inputText inputFocus";
         }
        });

        $(this).blur(function() {
         // 失去焦点时,如果值为空,则重新加上文本框默认值
         if (this.value == "" || this.value == $val) {
          this.value = $val;
          this.className = "inputText";
         }
        });
       });
      }

      input();
     })
    </script>
    </head>

    <body>
     <div class="fun">
      <h1>文本框聚焦清空默认值边框变色,离开焦点添加默认值</h1>
      <div class="text">
       <input type="text" class="inputText" value="1111" />
       <input type="text" class="inputText" value="2222" />
       <input type="text" class="inputText ss" value="82747" />
       <input type="text" class="inputText" value="094727" />
       <input type="text" class="inputText" value="249049" />
       <input type="text" class="inputText" value="333" />
       <input type="text" class="inputText" value="77777777" />
      </div>
     </div>
    </body>
    </html>

  • 相关阅读:
    DAY 06 PYTHON入门
    DAY 05 PYTHON入门
    DAY 04 PYTHON入门
    DAY 03 PYTHON入门
    DAY 02 PYTHON入门
    DAY 01 PYTHON入门
    RTC时钟和BKP的配置stm32
    Altium Designer画原理图时要紧凑
    串口的数据长度校验
    Centos7下创建文件夹 移动文件/文件夹 删除文件/文件夹 解压/文件夹打包压缩 命令整理
  • 原文地址:https://www.cnblogs.com/feong/p/5250110.html
Copyright © 2011-2022 走看看