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">
//找到第一個div
$(".div:first").css("color", "#CD00CD");
</script>
<script type="text/javascript">
//找到最后一個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
//選擇單個
$(".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>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
jQuery實(shí)現(xiàn)簡單的tab標(biāo)簽頁效果
這篇文章主要介紹了jQuery實(shí)現(xiàn)簡單的tab標(biāo)簽頁效果,涉及jQuery簡單元素遍歷與樣式動態(tài)操作相關(guān)技巧,需要的朋友可以參考下2016-09-09
jquery中取消和綁定hover事件的實(shí)現(xiàn)代碼
下面小編就為大家?guī)硪黄猨query中取消和綁定hover事件的實(shí)現(xiàn)代碼。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-06-06
PHP+MySQL+jQuery隨意拖動層并即時保存拖動位置實(shí)例講解
這篇文章主要介紹了PHP+MySQL+jQuery隨意拖動層并即時保存拖動位置的實(shí)現(xiàn)方法,感興趣的小伙伴們可以參考一下2015-10-10
JQuery+Ajax實(shí)現(xiàn)數(shù)據(jù)查詢、排序和分頁功能
這篇文章介紹了利用JQuery方便實(shí)現(xiàn)基于Ajax的數(shù)據(jù)查詢、排序和分頁功能,需要的朋友可以參考下2015-09-09
Visual Studio中的jQuery智能提示設(shè)置方法
Visual Studio中的jQuery智能提示設(shè)置方法,喜歡用vs2008開發(fā)的朋友可以參考下。2010-03-03
詳談jQuery中使用attr(), prop(), val()獲取value的異同
下面小編就為大家?guī)硪黄斦刯Query中使用attr(), prop(), val()獲取value的異同。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-04-04
ajax與json 獲取數(shù)據(jù)并在前臺使用簡單實(shí)例
這篇文章主要介紹了ajax與json 獲取數(shù)據(jù)并在前臺使用簡單實(shí)例的相關(guān)資料,需要的朋友可以參考下2017-01-01
解析頁面加載與js函數(shù)的執(zhí)行 onload or ready
這篇文章主要介紹了頁面加載與js函數(shù)的執(zhí)行 onload or ready 需要的朋友可以過來參考下,希望對大家有所幫助2013-12-12

