JavaScript组件之JQuery(A~Z)教程(基于Asp.net运行环境)四

15). 改变表格行为(by calss property)

 1 <head runat="server">
 2     <title>改变表格行为</title>
 3     <script src=Resources/js/jquery-1.2.1.js type="text/javascript"></script>        
 4         <script type="text/javascript">
 5         $(document).ready(function(){ 
 6                 $(".stripe tr").mouseover(function(){ 
 7                         //如果鼠标移到class为stripe的表格的tr上时,执行函数
 8                         $(this).addClass("悬浮");}).mouseout(function(){
 9                                         //给这行添加class值为over,并且当鼠标一出该行时执行函数
10                         $(this).removeClass("悬浮");})  //移除该行的class
11                 $(".stripe tr:even").addClass("偶数");
12                     //给class为stripe的表格的偶数行添加class值为:偶数
13                 $(".stripe tr:odd").addClass("奇数");
14                     //给class为stripe的表格的偶数行添加class值为:奇数       
15         });
16         </script>
17         <style>
18         th {
19                 background:#0066FF;
20                 color:#FFFFFF;
21                 line-height:20px;
22                 height:30px;
23         }
24         
25         td {
26                 padding:6px 11px;
27                 border-bottom:1px solid #95bce2;
28                 vertical-align:top;
29                 text-align:center;
30         }
31         
32         td * {
33                 padding:6px 11px;
34         }
35         
36         tr.奇数 td {
37                 background:#ecf6fc;  /*设置奇数行颜色*/
38         }
39         tr.偶数 td {
40                 background:#ecf6ee;  /*设置偶数行颜色*/
41         }
42         
43         tr.悬浮 td {
44                 background:#6699ff;  /*这个将是鼠标高亮行的背景色*/
45         }
46         
47         </style>
48
49 </head>
50 <body>
51     <form id="form1" runat="server">
52     <div>
53         <table class="stripe" width="50%" border="0" cellspacing="0" cellpadding="0">            
54             <thead>
55               <tr>
56                 <th>姓名</th>
57                 <th>年龄</th>
58                 <th>QQ</th>
59                 <th>Email</th>
60               </tr>
61             </thead>
62             <tbody>
63               <tr>
64                 <td>张三</td>
65                 <td>20</td>
66                 <td>00000</td>
67                 <td>******</td>
68               </tr>
69               <tr>
70                 <td>李四</td>
71                 <td>20</td>
72                 <td>00000</td>
73                 <td>******</td>
74               </tr>
75               <tr>
76                 <td>小刘</td>
77                 <td>20</td>
78                 <td>00000</td>
79                 <td>*****</td>
80               </tr>
81             </tbody>
82         </table>
83
84     </div>
85     </form>
86 </body>

16). 操作jQuery属性示例

 1 <head runat="server">
 2     <title>操作元素属性</title>
 3     <style>
 4         .blue {
 5                 background:#6699FF;
 6                 color:#FFFFFF;
 7                 line-height:20px;
 8                 height:30px;
 9         }
10     </style>   
11     <script src=Resources/js/jquery-1.2.1.js></script>
12     <script type="text/javascript">
13         function ChangeElementStyleAndProperty()
14         {           
15             if( i == 0 )
16                 $("#tb").css("background","#6699ff")                 //设定元素背景色
17             if( i == 1 )
18                 $("#tb").height(300);                                //设定高度
19             if( i == 2 )
20                 $("#tb").width(200);                                 //设定宽度
21             if( i == 3 )
22                 $("#tb").css({ color: "black", background: "blue" });//设置我个属性
23             if( i == 4 )
24                 $("#tb").addClass("blue");                           //添加class
25             if( i == 5 )
26                 $("#tb").removeClass("blue");                        //删除class
27             if( i == 6 )
28                 $("#tb").toggleClass("blue");                        //交替添加class或删除class.
29             i++;
30             if( i == 6 ) i = 0;
31         }
32         var i = 0;
33     </script>    
34 </head>
35 <body>
36     <form id="form1" runat="server">
37     <div>
38          <input id="btn" type=button value="Animate事件测试" οnclick="ChangeElementStyleAndProperty();" />
39          <table id="tb"><tr><td>Hi King!</td></tr></table>
40     </div>
41     </form>
42 </body>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值