zoukankan      html  css  js  c++  java
  • 表单元素焦点的获取和失去

    HTML:
    <!DOCTYPE >

    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style type="text/css">
    * {
    /*margin: 0px;
    padding: 0;*/
    font-family: "微软雅黑", "arial", " sans-serif";
    font-size: 16px;
    }

    body {
    margin: 20px;
    }

    .focus {
    border: 1px solid #f00;
    background: #fcc;
    }
    </style>
    <script type="text/javascript" src="js/jquery-2.2.2.min.js">
    </script>

    <script type="text/javascript">
    $(function () {
    $(":input")
    .focus(function () {
    $(this).addClass("focus");
    })

    .blur(function () {
    $(this).removeClass("focus");
    })
    });
    </script>
    </head>

    <body>
    <form>
    <fieldset style=" 370px;height: 136px;">
    <legend>登录界面</legend>
    <div>
    <label for="username">用户:</label>
    <input id="username" type="text"/>
    </div>
    <div>
    <label for="pass">密码:</label>
    <input id="pass" type="password"/>
    </div>
    </fieldset>
    </form>

    </body>

    </html>

    result:

    运行:


    HTML:
    <!DOCTYPE >
    <html>

    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>无标题文档</title>
    <style type="text/css">
    * {
    /*margin: 0px;
    padding: 0;*/
    font-family: "微软雅黑", "arial", " sans-serif";
    font-size: 16px;
    }

    body {
    margin: 20px;
    }

    .focus {
    border: 1px solid #f00;
    background: #fcc;
    }
    </style>
    <script type="text/javascript" src="js/jquery-2.2.2.min.js">
    </script>

    <script type="text/javascript">
    $(function () {
    $(":input").bind({
    focus: function () {
    $(this).addClass("focus");
    },
    blur: function () {
    $(this).removeClass("focus");
    }
    })


    });
    </script>
    </head>

    <body>
    <form>
    <fieldset style=" 370px;height: 136px;">
    <legend>登录界面</legend>
    <div>
    <label for="username">用户:</label>
    <input id="username" type="text"/>
    </div>
    <div>
    <label for="pass">密码:</label>
    <input id="pass" type="password"/>
    </div>
    </fieldset>
    </form>

    </body>

    </html>


  • 相关阅读:
    数据挖掘:基本概念理解
    Linux:数据库服务(Mysql安装及链接、远程链接、genelog)
    Linux:WebServer(Nginx 虚拟主机配置与伪静态实现)
    Linux:WebServer(Apacge)
    单例和多线程
    Redis注册成服务
    Redis基础学习
    sqlserver查询使用with(nolock)详解
    JAVA设计模式-策略模式
    JAVA设计模式-代理模式
  • 原文地址:https://www.cnblogs.com/theWayToAce/p/5497818.html
Copyright © 2011-2022 走看看