jQuery基本过滤选择器

来源:互联网 发布:qq群机器人源码 编辑:程序博客网 时间:2024/05/02 02:26

:animated Selector

选择所有和选择器同时在运行的动画元素


:eq() Selector

选择匹配元素集合中索引为n的元素

译者注:匹配给定索引值的元素,索引值是从0开始的。


:even Selector

选择所有索引值为偶数的元素,同见odd.

译者注:选择匹配元素中索引值为偶数的元素,索引值是从0开始的。


:first Selector

选择第一个匹配的元素


:focus selector

选择正在被focused的元素


:gt() Selector

选择所有比给定索引值大的匹配元素

译者注:匹配所有大于给定索引值的元素,索引值是从0开始的。


:header Selector

选择所有的标题元素比如h1,h2,h3等等


:last Selector

选择最后一次匹配的元素


:lt() Selector

选择所有比给定索引值小的所有匹配的元素


:not() Selector

选择所有和给定选择器不匹配的元素


:odd Selector

选择所有索引值为奇数的元素,同见even



<script>    $("#run").click(function(){//改变所有正在运行动画的div元素的颜色      $("div:animated").toggleClass("colored");    });    function animateIt() {      $("#mover").slideToggle("slow", animateIt);    }    animateIt();</script>
<script>$("td:eq(2)").css("color", "red");//查找第三个td</script>
<script>$("tr:even").css("background-color", "#bbbbff");//查找index是偶数的table行,匹配第一,第三行等等(索引是0,2,4等)</script>
<script>$("tr:first").css("font-style", "italic");//查找第一行</script>
 <script>$( "#content" ).delegate( "*", "focus blur", function( event ) {//添加class到所有focus的元素上    var elem = $( this );    setTimeout(function() {       elem.toggleClass( "focused", elem.is( ":focus" ) );    }, 0);});</script>
<script>$("td:gt(4)").css("text-decoration", "line-through");//查找TD#5(元素的text值)或更高,记住:索引从0开始</script>
<script>$(":header").css({ background:'#CCC', color:'blue' });//给页面上的所有标题元素添加背景和文本颜色</script>
<script>$("tr:last").css({backgroundColor: 'yellow', fontWeight: 'bolder'});//查找最后一个table行</script>
<script>$("td:lt(4)").css("color", "red");//查找比索引值4小的所有TD元素</script>
<script>  $("input:not(:checked) + span").css("background-color", "yellow");  $("input").attr("disabled", "disabled");//查找所有未被checked的元素,并给下一个同级span元素添加highlights。注意,当点击checkboxes的时候不会有所改变,因为没有单击事件被关联</script>
<script>$("tr:odd").css("background-color", "#bbbbff");//查找索引为奇数的table行,匹配第二,第四等等行(索引是1,3,5等等)</script>
原创粉丝点击