jQuery基本篩選選擇器實(shí)例代碼
本文實(shí)例為大家分享了jQuery基本篩選選擇器的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content="text/html; charset=utf-8" /> <title></title> <link rel="stylesheet" href="imooc.css" type="text/css"> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </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"> //找到第一個(gè)div $(".div:first").css("color", "#CD00CD"); </script> <script type="text/javascript"> //找到最后一個(gè)div $(".div:last").css("color", "#CD00CD"); </script> <script type="text/javascript"> //:even 選擇所引值為偶數(shù)的元素,從 0 開始計(jì)數(shù) $(".div:even").css("border", "3px groove red"); </script> <script type="text/javascript"> //:odd 選擇所引值為奇數(shù)的元素,從 0 開始計(jì)數(shù) $(".div:odd").css("border", "3px groove blue"); </script> <h3>:eq/:gt/:lt</h3> <div class="left"> <div class="aaron"> <p>:lt(3)</p> </div> <div class="aaron"> <p>:lt(3)</p> </div> <div class="aaron"> <p>:eq(2)</p> </div> <div class="aaron"> </div> <div class="aaron"> <p>:gt(3)</p> </div> <div class="aaron"> <p>:gt(3)</p> </div> </div> <script type="text/javascript"> //:eq //選擇單個(gè) $(".aaron:eq(2)").css("border", "3px groove blue"); </script> <script type="text/javascript"> //:gt 選擇匹配集合中所有索引值大于給定index參數(shù)的元素 $(".aaron:gt(3)").css("border", "3px groove blue"); </script> <script type="text/javascript"> //:lt 選擇匹配集合中所有索引值小于給定index參數(shù)的元素 //與:gt相反 $(".aaron:lt(2)").css("color", "#CD00CD"); </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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實(shí)現(xiàn)簡(jiǎn)單的tab標(biāo)簽頁(yè)效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單的tab標(biāo)簽頁(yè)效果,涉及jQuery簡(jiǎn)單元素遍歷與樣式動(dòng)態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-09-09jquery中取消和綁定hover事件的實(shí)現(xiàn)代碼
下面小編就為大家?guī)?lái)一篇jquery中取消和綁定hover事件的實(shí)現(xiàn)代碼。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2016-06-06PHP+MySQL+jQuery隨意拖動(dòng)層并即時(shí)保存拖動(dòng)位置實(shí)例講解
這篇文章主要介紹了PHP+MySQL+jQuery隨意拖動(dòng)層并即時(shí)保存拖動(dòng)位置的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2015-10-10JQuery+Ajax實(shí)現(xiàn)數(shù)據(jù)查詢、排序和分頁(yè)功能
這篇文章介紹了利用JQuery方便實(shí)現(xiàn)基于Ajax的數(shù)據(jù)查詢、排序和分頁(yè)功能,需要的朋友可以參考下2015-09-09Visual Studio中的jQuery智能提示設(shè)置方法
Visual Studio中的jQuery智能提示設(shè)置方法,喜歡用vs2008開發(fā)的朋友可以參考下。2010-03-03詳談jQuery中使用attr(), prop(), val()獲取value的異同
下面小編就為大家?guī)?lái)一篇詳談jQuery中使用attr(), prop(), val()獲取value的異同。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來(lái)看看吧2017-04-04ajax與json 獲取數(shù)據(jù)并在前臺(tái)使用簡(jiǎn)單實(shí)例
這篇文章主要介紹了ajax與json 獲取數(shù)據(jù)并在前臺(tái)使用簡(jiǎn)單實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-01-01解析頁(yè)面加載與js函數(shù)的執(zhí)行 onload or ready
這篇文章主要介紹了頁(yè)面加載與js函數(shù)的執(zhí)行 onload or ready 需要的朋友可以過來(lái)參考下,希望對(duì)大家有所幫助2013-12-12jquery中輸入驗(yàn)證中一個(gè)不錯(cuò)的效果
在表單的輸入驗(yàn)證中,經(jīng)常要當(dāng)用戶沒能正確輸入后,要提示“XXXX輸入錯(cuò)誤”這一類的信息,如何能搞到動(dòng)態(tài)一點(diǎn)呢,今天發(fā)現(xiàn)jquery中的一個(gè)不錯(cuò)的效果,筆記之。2010-08-08