jQuery学习笔记(5)--表单域获得焦点和失去焦点样式变化

本文介绍如何利用jQuery库为HTML输入框实现聚焦时的样式变化,包括边框颜色和背景色的变化。
 1 <html xmlns="http://www.w3.org/1999/xhtml">
 2 <head runat="server">
 3     <title></title>
 4     <script src="Scripts/jquery-1.4.1.min.js" type="text/javascript"></script>
 5     <style type="text/css">
 6         
 7         <%-- IE6不支持这种方法--%>
 8         <%--input:focus, textarea:focus
 9         {
10             border: 1px solid #f00;
11             background:#fcc;
12         }--%>
13         
14         .focus
15         {
16             border: 1px solid gray;
17             background:gray;
18         }
19         
20         
21     </style>
22     <script type="text/javascript">
23 
24         $(function () {
25             $(":input").focus(function () {
26                 $(this).addClass("focus");
27             }).blur(function () {
28                 $(this).removeClass("focus");
29             });
30 
31         });
32 
33     </script>
34 </head>
35 <body>
36     <form id="form1" runat="server" method="post">
37     <div style="width: 300px; border: 1px solid black">
38         <fieldset>
39             <legend>个人基本信息</legend>
40             <div>
41                 <label for="username">
42                     名称:</label>
43                 <input id="username" type="text" />
44             </div>
45             <div>
46                 <label for="pass">
47                     密码:</label>
48                 <input id="pass" type="password" />
49             </div>
50             <div>
51                 <label for="msg">
52                     详细信息:</label>
53                 <textarea id="msg" rows="5" cols="10"></textarea>
54             </div>
55         </fieldset>
56     </div>
57     </form>
58 </body>
59 </html>
View Code

效果图:

转载于:https://www.cnblogs.com/hshuai/p/4252502.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值