日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

jQuery教程06-基本筛选选择器

發布時間:2025/3/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 jQuery教程06-基本筛选选择器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

jQuery選擇器之基本篩選選擇器

很多時候我們不能直接通過基本選擇器與層級選擇器找到我們想要的元素,為此jQuery提供了一系列的篩選選擇器用來更快捷的找到所需的DOM元素。篩選選擇器很多都不是CSS的規范,而是jQuery自己為了開發者的便利延展出來的選擇器

1、篩選選擇器

篩選選擇器的用法與CSS中的偽元素相似,選擇器用冒號“:”開頭,通過一個列表,看看基本篩選器的描述:

2、注意事項:

:eq(), :lt(), :gt(), :even, :odd 用來篩選他們前面的匹配表達式的集合元素,根據之前匹配的元素在進一步篩選,注意jQuery合集都是從0開始索引
gt是一個段落篩選,從指定索引的下一個開始,gt(1) 實際從2開始

3、示例代碼:

<!DOCTYPE html> <html> <head><meta http-equiv="Content-type" content="text/html; charset=utf-8" /><title>基本篩選選擇器</title><script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script><style>.left {width: auto;height: 120px;}.left div {width: 70px;height: 70px;padding: 5px;margin: 5px;float: left;background: #bbffaa;border: 1px solid #ccc;}.bottom {width: 800px;}.bottom div,.bottom span {display: block;width: 80px;height: 80px;margin: 5px;background: #bbffaa;float: left;font-size: 14px;}.bottom .small {width: 60px;height: 25px;font-size: 12px;background: #fab;}</style> </head> <body><h2>基本篩選器</h2><h3>:first/:last/:even/:odd</h3><div class="left"><div class="div"><p>div:first</p><p>:even</p></div><div class="div"><p>:odd</p></div><div class="div"><p>:even</p></div><div class="div"><p>:odd</p></div><div class="div"><p>:even</p></div><div class="div"><p>div:last</p><p>:odd</p></div></div><script type="text/javascript">//找到第一個div$('.div:first').css("color", "#CD00CD");</script><script type="text/javascript">//找到最后一個div$('.div:last').css("color", "#CD00CD");</script><script type="text/javascript">//:even 選擇所引值為偶數的元素,從 0 開始計數$('.div:even').css("border", "3px groove red");</script><script type="text/javascript">//:odd 選擇所引值為奇數的元素,從 0 開始計數$('.div:odd').css("border", "3px groove blue");</script><h3>:eq/:gt/:lt</h3><div class="left"><div class="aaron"><p>:lt(3) and :eq(0)</p></div><div class="aaron"><p>:lt(3) and :eq(1)</p></div><div class="aaron"><p>:lt(3) and :eq(2)</p></div><div class="aaron"><p>:eq(3)</p></div><div class="aaron"><p>:gt(3) and :eq(4)</p></div><div class="aaron"><p>:gt(3) and :eq(5)</p></div></div><script type="text/javascript">//:eq//選擇單個$('.aaron:eq(2)').css("border", "3px groove blue");</script><script type="text/javascript">//:gt 選擇匹配集合中所有索引值大于給定index參數的元素$('.aaron:eq(3)').css("border", "3px groove green");</script><script type="text/javascript">//:gt 選擇匹配集合中所有索引值大于給定index參數的元素$('.aaron:gt(3)').css("border", "3px groove red");</script><script type="text/javascript">//:lt 選擇匹配集合中所有索引值小于給定index參數的元素//與:gt相反$('.aaron:lt(3)').css("color", "red");</script><h3>:not</h3><div class="left"><div><input type="checkbox" name="a" /><p>Aaron</p></div><div><input type="checkbox" name="b" /><p>數據</p></div><div><input type="checkbox" name="c" checked="checked" /><p>其他</p></div></div><script type="text/javascript">//:not 選擇所有元素去除不匹配給定的選擇器的元素//選中所有緊接著沒有checked屬性的input元素后的p元素,賦予顏色$('input:not(:checked) + p').css("background-color", "#CD00CD");</script> </body></html>

總結

以上是生活随笔為你收集整理的jQuery教程06-基本筛选选择器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。