jquery总结

id选择器只能选定第一个满足条件的元素

class选择器可以选定一类满足条件的元素

text(),html(),val(),attr()等操作类型的函数,作用对象是前面选择器选定的元素.选定的元素可能有很多个,所以text(function(index,old){})

attr()可以指定多个属性

$("button").click(function(){
  $("#w3s").attr({
    "href" : "http://www.w3school.com.cn/jquery",
    "title" : "W3School jQuery Tutorial"
  });
});
attr可以对不同的元素指定不同的属性:
$("button").click(function(){
  $("#w3s").attr("href", function(i,origValue){
    return origValue + "/jquery";
  });
});
最复杂的一个实例
<html>
    <head>
        <script type="text/javascript" src='lib/jquery.js'>
            
        </script>
    </head>
    <body>
        <span class='haha' >weidiao is great</span><br>
        <span class='haha' >weidiao is great</span><br>
        <span class='haha' >weidiao is great</span><br> 
    </body>
    <script type="text/javascript">
        $('.haha').attr({
            id:function(ind,oldvalue){
                return 'id'+ind;
            },
            style:function(ind,oldValue){
                return "style"+ind;
            }
        })
    </script>
</html>
原文地址:https://www.cnblogs.com/weiyinfu/p/5514611.html