码迷,mamicode.com
首页 > Web开发 > 详细

jQuery——表单应用(1)

时间:2017-07-04 17:00:48      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:详细   user   head   type   结果   code   分时   input   post   

实现结果:聚焦表单的input部分时,input格式变更为CSS样式(获取和失去焦点改变样式)

HTML:

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
        <link type="text/css" href="01.css" rel="stylesheet"/>
        <script type="text/javascript" src="jquery.js"></script>
    </head>
    <body>
        <form action="#" method="post" id="regForm">
            <fieldset>
                <legend>个人基本信息</legend>
                <div>
                    <label for="username">名称:</label>
                    <input id="username" type="text"/>
                </div>
                <div>
                    <label for="password">密码:</label>
                    <input id="password" type="password"/>
                </div>
                <div>
                    <label for="msg">详细信息:</label>
                    <textarea id="msg"></textarea>
                </div>
            </fieldset>
        </form>
        <script type="text/javascript">
            $(function(){
                $("input").focus(function(){
                    $(this).addClass("focus");
                }).blur(function(){
                    $(this).removeClass("focus");
                })
            })
        </script>
    </body>
</html>

CSS:

.focus{
    border: 1px solid red;
    background: red;
}

 

jQuery——表单应用(1)

标签:详细   user   head   type   结果   code   分时   input   post   

原文地址:http://www.cnblogs.com/sunshine-blog/p/7117373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!