2012年4月13日 星期五

jQuery過濾器

資料來源KingKong Bruce記事
jQuery過濾器

過濾器

說明

範例

:animated

選擇正在執行動畫效果的元素

$(':animated')或.filter(":animated")

:eq(index)

等於索引值(索引從0開始)

$(':eq(index)')或$('Selector').eq(index)

:even

選擇奇數索引值,會選擇元素1與元素3;即索引值的0,2,...

$(':even')或.filter(':even')

:first

選擇第一個符合的元素

$(':first')或.filter(':first')

:gt(index)

大於索引值的對應元素;索引從0開始

$(':gt(index)')或$('Selector').slice(index)

:header

選擇所有h1,h2,h3,h4,h5,h6元素

$(':header')或.filter(':header')

:last

選擇最後一個符合的元素

$(':last')或.filter(':last')

:lt(index)

小於索引值的對應元素索引從0開始

$(':lt(index)')或$('Selector').slice(0,index)

:not(Selector)

排除selector內元素

$(':not(selector)')

:odd

選擇偶數索引值對應的元素;元素2,4,6,...;:odd會選擇元素2與元素3;即索引值的1,3,...

$(':odd')
[name|="value"] 選擇指定屬性等於字串值或以該字串為前綴的值(以字串後跟著一個連字符號"-")的元素。

這個過濾器是引入CSS規範來處理語言屬性。
$('[attribute|=value]')
[name*="value"] 選擇指定屬性包含特定字串值,不論在字串中的位置。 $('[attribute*=value]')
[name~="value"] 選擇指定屬性包含特定字串值,字串用空格分隔。 $('[attribute~=value]')
[name$="value"] 選擇指定屬性的字串是以字串值結尾。

這個比較區分大小寫。
$('[attribute$=value]')
[name="value"] 選擇指定屬性的字串等於字串值。 $('[attribute=value]')
[name!="value"] 選擇沒有指定屬性的元素,或指定屬性的字串不等於字串值。 $('[attribute!=value]')
[name^="value"] 選擇指定屬性的字串是以字串值開頭。 $('[attribute^=value]')
[name] 選擇所有具有指定屬性的元素,該屬性的字串可以是任何值。 $('[attribute]')
[name="value"][name2="value2"] 選擇符合所有指定屬性過濾器的元素 $('[attribute1=value1][attribute2=value2]')

選擇器

說明

範例

:button

選擇button元素和type="button"的input元素

$(':button')

:checkbox

選擇type="checkbox"的input元素

$(':checkbox')

:checked

選擇已勾選(checkbox)或已選擇(radio)的input元素

$(':checked')

:disabled

選擇設定disabled屬性的input元素

$(':disabled')

:enabled

選擇未設定disabled屬性的input元素

$(':enabled')

:focus

選擇目前焦點所在的元素,注意,不限於input元素

$(':focus')

:file

選擇type="file"屬性的input元素

$(':file')

:image

選擇type="image"屬性的input元素

$(':image')

:input

選擇input、textarea、select、button元素

$(':input')

:password

選擇type="password"屬性的input元素

$(':password')

:radio

選擇type="radio"屬性的input元素

$(':radio')

:reset

選擇type="reset"屬性的input元素

$(':reset')

:selected

選擇所有option元素裡被選擇項目

$(':selected')

:submit

選擇button元素與type="submit"屬性的input元素

$(':submit')

:text

選擇type="text"屬性的input元素

$(':text')

沒有留言:

張貼留言