W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
根據(jù)選擇器、DOM元素或 jQuery 對象來檢測匹配元素集合,如果其中至少有一個元素符合這個給定的表達(dá)式就返回true。
如果沒有元素符合,或者表達(dá)式無效,都返回'false'。'''注意:'''在jQuery 1.3中才對所有表達(dá)式提供了支持。在先前版本中,如果提供了復(fù)雜的表達(dá)式,比如層級選擇器(比如 + , ~ 和 > ),始終會返回true
字符串值,包含供匹配當(dāng)前元素集合的選擇器表達(dá)式。
現(xiàn)有的jQuery對象,以匹配當(dāng)前的元素。
一個用于匹配元素的DOM元素。
一個函數(shù)用來作為測試元素的集合。它接受一個參數(shù)index,這是元素在jQuery集合的索引。在函數(shù), this指的是當(dāng)前的DOM元素。
由于input元素的父元素是一個表單元素,所以返回true。
<form><input type="checkbox" /></form>
$("input[type='checkbox']").parent().is("form")
true
判斷點(diǎn)擊li標(biāo)簽增加背景色為紅色,如果點(diǎn)擊的是第2個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 tag
list item 2 - two strong tags
list item 3
list item 4
list item 5
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: