DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> JQuery篩選器全系列介紹
JQuery篩選器全系列介紹
編輯:JQuery特效代碼     

1.選擇對象

1).基本

·#id 根據給定的ID匹配一個元素。例如:$("#id")
·element 根據給定的元素名匹配所有元素。例如:$("div")
·.class 根據給定的類匹配元素。例如:$(".style1");
·* 匹配所有元素。例如:$("*")
·selector1,selector2,selectorN 將每一個選擇器匹配到的元素合並後一起返回。例如:$("#id,div,.style1")

2).表單

·:button 匹配所有按鈕。例如:$(":button")
·:checkbox 匹配所有復選框。例如:$(":checkbox")
·:file 匹配所有文件域。例如:$(":File")
·:hidden 匹配所有不可見元素,或者type為hidden的元素。例如:$("input:hidden")
·:image 匹配所有圖像域。例如:$(":image")
·:input 匹配所有 input, textarea, select 和 button 元素。例如:$(":input")
·:password 匹配所有密碼框。例如:$(":password")
·:radio 匹配所有單選按鈕。例如:$(":radio")
·:reset 匹配所有重置按鈕。例如:$(":reset")
·:submit 匹配所有提交按鈕。例如:$(":submit")
·:text 匹配所有的單行文本框。例如:$(":text")
·:header 匹配如 h1, h2, h3之類的標題元素。例如:$(":header").css("background", "#EEE");

2.篩選條件

1).屬性篩選

·[attribute*=value] 匹配給定的屬性是以包含某些值的元素。例如:$("input[name*='man'")
·[attribute!=value] 匹配所有含有指定的屬性,但屬性不等於特定值的元素。例如:$(input[name!='man');
·[attribute$=value] 匹配給定的屬性是以某些值結尾的元素。例如:$("input[name$='man']")
·[attribute=value] 匹配給定的屬性是某個特定值的元素。例如:$("input[name='man']");
·[attribute] 匹配包含給定屬性的元素。例如:$("div[id]")
·[attribute^=value] 匹配給定的屬性是以某些值開始的元素。例如:$("input[name^='man']")
·[selector1][selector2][selectorN] 同時滿足多個條件。例如:$("input[id][name$='man']")
·:hidden 匹配所有的不可見元素。例如:$("tr:hidden")
·:visible 匹配所有的可見元素。例如:$("tr:visible")
·:checked 匹配所有選中的被選中元素(復選框、單選框等,不包括select中的option)。例如:$("input:checked")
·:disabled 匹配所有不可用元素。例如:$("input:disabled")
·:enabled 匹配所有可用元素。例如:$("input:enabled")
·:selected 匹配所有選中的option元素。例如:$("select option:selected")

2).內容篩選

·:contains(text) 匹配包含給定文本的元素。例如:$("div:contains('John')")
·:empty 匹配所有不包含子元素或者文本的空元素。例如:$("td:empty")
·:has(selector) 匹配含有選擇器所匹配的元素的元素。例如:$("div:has(p)");
·:parent 匹配含有子元素或者文本的元素。例如:$("td:parent")

3).層級篩選

·ancestor descendant 在給定的祖先元素下匹配所有的後代元素。例如:$("form input")
·parent > child 在給定的父元素下匹配所有的子元素。例如:$("form > input")
·prev + next 匹配所有緊接在 prev 元素後的 next 元素。例如:$("label + input")
·prev ~ siblings 匹配 prev 元素之後的所有 siblings 元素。例如:$("form ~ input")
·:first-child 匹配第一個子元素。例如:$("ul li:first-child")
·:last-child 匹配最後一個子元素。例如:$("ul li:last-child")
·:nth-child(index/even/odd/equation) 匹配其父元素下的第N個子或奇偶元素。例如:$("ul li:nth-child(2)")
·:only-child 如果某個元素是父元素中唯一的子元素,那將會被匹配。例如:$("ul li:only-child")

4).方法篩選

·:animated 匹配所有正在執行動畫效果的元素。例如:$("div:animated");
·:eq(index) 匹配一個給定索引值的元素。例如:$("tr:eq(1)")
·:even 匹配所有索引值為偶數的元素,從 0 開始計數。例如:$("tr:even")
·:first 匹配找到的第一個元素。例如:$("tr:first")
·:gt(index) 匹配所有大於給定索引值的元素,從 0 開始計數。例如:$("tr:gt(0)")
·:last 匹配找到的最後一個元素。例如:$("tr:last")
·:lt(index) 匹配所有小於給定索引值的元素。例如:$("tr:lt(2)")
·:not(selector) 去除所有與給定選擇器匹配的元素。例如:$("input:not(:checked)")
·:odd 匹配所有索引值為奇數的元素,從 0 開始計數。例如:$("tr:odd")

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved