jquery attr()和prop()方法的使用

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>wrap</title>
 6     <script type="text/javascript" src="../jquery/jquery-1.11.3.min.js"></script>
 7 </head>
 8 <body>
 9 <a href="http://www.baidu.com" class="baidu">百度</a>
10 <a href="http://www.souhu.com" class="souhu">百度</a>
11 <a href="http://www.xinlang.com" class="xinlng">百度</a>
12 
13 <script type="text/javascript">
14 
15     $(document).ready(function () {
16         var __attr = $("a").attr("href");//获取属性值
17         console.log(__attr);
18 
19         $("a").each(function (index, elem) {// index是索引 elem当前元素
20 //            var num=$(elem).attr("href","www.eshenghuo365.com");//设置属性值
21 //            var num=$(elem).attr({'href':'www.eshenghuo365.com','title':"e生活"});//设置多个属性值
22 //        $(elem).attr("href",function(index,value){//动态设置属性 index是索引 value是当前属性值
23 //            if(value.indexOf('souhu')){
24 //                $(this).next().css("font-size","100px")
25 //
26 //            }
27 //        });
28 //       $("a:odd").removeAttr("href"); //删除偶数行的属性
29 //       $("a:even").removeAttr("href");//删除奇数行的属性
30             console.log($(elem).prop("className"));
31 //            console.log(num);
32 
33         });
34     });
35 
36 </script>
37 </body>
38 </html>

 

posted @ 2016-04-03 21:53  Window2016  阅读(420)  评论(0编辑  收藏  举报