首页 > Web开发 > 详细

jQuery——表单应用(1)

时间:2017-07-04 16:58:01      阅读:241      评论:0      收藏:0      [点我收藏+]

实现结果:聚焦表单的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)

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!