?
This document uses PHP Chinese website manual Release
根據(jù)選擇器、DOM元素或 jQuery 對(duì)象來(lái)檢測(cè)匹配元素集合,如果其中至少有一個(gè)元素符合這個(gè)給定的表達(dá)式就返回true。
如果沒有元素符合,或者表達(dá)式無(wú)效,都返回'false'。 '''注意:'''在jQuery 1.3中才對(duì)所有表達(dá)式提供了支持。在先前版本中,如果提供了復(fù)雜的表達(dá)式,比如層級(jí)選擇器(比如 + , ~ 和 > ),始終會(huì)返回true
字符串值,包含供匹配當(dāng)前元素集合的選擇器表達(dá)式。
現(xiàn)有的jQuery對(duì)象,以匹配當(dāng)前的元素。
一個(gè)用于匹配元素的DOM元素。
一個(gè)函數(shù)用來(lái)作為測(cè)試元素的集合。它接受一個(gè)參數(shù)index,這是元素在jQuery集合的索引。在函數(shù), this指的是當(dāng)前的DOM元素。
由于input元素的父元素是一個(gè)表單元素,所以返回true。
<form><input type="checkbox" /></form>
$("input[type='checkbox']").parent().is("form")
true
判斷點(diǎn)擊li標(biāo)簽增加背景色為紅色,如果點(diǎn)擊的是第2個(gè)strong,當(dāng)前的li增加背景色為綠色,
<ul> <li><strong>list</strong> item 1 - one strong tag</li> <li><strong>list</strong> item <strong>2</strong> - two <span>strong tags</span></li> <li>list item 3</li> </ul>
$("li").click(function() { var $li = $(this), isWithTwo = $li.is(function() { return $('strong', this).length === 2; }); if ( isWithTwo ) { $li.css("background-color", "green"); } else { $li.css("background-color", "red"); } });
list item 1 - one strong taglist item 2 - two strong tagslist item 3list item 4list item 5