zoukankan      html  css  js  c++  java
  • jquery获取和失去焦点改变样式

    第一种:(文本框获取焦点后,它的颜色会有所变化,当失去焦点的时候,恢复为原来的样子)

    <html>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script type="text/javascript" src="jquery-1.11.3.js"></script>
        <style type="text/css">
            input:focus ,textarea:focus{
                border: 1px solid #f00;
                background: #fcc;
            }
        </style>
        
    <body>
        <form action="#" method="POST" id="regForm">
            <fieldset>
                <legend>个人基本信息</legend>
                <div>
                    <label for="username">名称:</label>
                    <input id="username" type="text">
                </div>
                <div>
                    <label for="pass">密码:</label>
                    <input id="pass" type="password">
                </div>
                <div>
                    <label for="msg">详细信息:</label>
                    <textarea id="msg"></textarea>
                </div>
                
            </fieldset>
        </form>
    
    </body>
    </html>

    只不过IE中不兼容

    第二种IE兼容:

     1 <html>
     2     <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
     3     <script type="text/javascript" src="jquery-1.11.3.js"></script>
     4     <style type="text/css">
     5         
     6         .focus{
     7             border: 1px solid #f00;
     8             background: #fcc;
     9         }
    10     </style>
    11      <script type="text/javascript">
    12         $(function(){
    13             $(":input").focus(function(){
    14                 $(this).addClass("focus")
    15             }).blur(function(){
    16                 $(this).removeClass("focus");
    17             })
    18         })
    19         
    20      </script>
    21 <body>
    22     <form action="#" method="POST" id="regForm">
    23         <fieldset>
    24             <legend>个人基本信息</legend>
    25             <div>
    26                 <label for="username">名称:</label>
    27                 <input id="username" type="text">
    28             </div>
    29             <div>
    30                 <label for="pass">密码:</label>
    31                 <input id="pass" type="password">
    32             </div>
    33             <div>
    34                 <label for="msg">详细信息:</label>
    35                 <textarea id="msg"></textarea>
    36             </div>
    37             
    38         </fieldset>
    39     </form>
    40 
    41 </body>
    42 </html>
  • 相关阅读:
    get ,post接口测试
    jmeter接口测试 day11
    接口笔记,day01
    python 列表、元组 达内笔记
    linux 笔记达内03
    linux 笔记达内02
    linux 笔记达内01
    Linux/Unix系统下常用的命令
    PageObjectModel页面对象模型(03)
    selenium,实现ECShop后台登录模块测试代码(2)
  • 原文地址:https://www.cnblogs.com/adaonling/p/5214252.html
Copyright © 2011-2022 走看看