首頁  >  文章  >  web前端  >  jQuery中end方法的用法

jQuery中end方法的用法

巴扎黑
巴扎黑原創
2017-06-24 11:14:512254瀏覽

我們在對結果集使用find、filter等方法時,會改變結果集。

這種改變原先結果集的方法被稱為destructive jQuery method

jQuery cookbook有如下定義:

#A destructive operation is any operation that changes the set of matched jQuery elements, which means any traversing or manipulation method that returns a jQuery object, including##(( , andSelf(), children(), closes(), filter(), find(), map(), next(), nextAll(), not(), parent(), parents(), prev(), prevAll(), siblings(), slice(), clone(), appendTo(), prependTo(), insertBefore<a href="http://www.php.cn/java/java-Before.html" target="_blank">(), insertAfter(), replaceAll()</a>。

具體用法如下

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
</head>
<body>
	<p>Text</p>
	<p class="middle">Middle <span>Text</span></p>
	<p>Text</p>
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script type="text/javascript">
	alert($(&#39;p&#39;).filter(&#39;.middle&#39;).length); // alerts 1
	alert($(&#39;p&#39;).filter(&#39;.middle&#39;).end().length); // alerts 3
	alert($(&#39;p&#39;).filter(&#39;.middle&#39;).find(&#39;span&#39;).end().end().length); // alerts 3
</script>
</body>
</html>

當對

$('p')的結果執行filter('.middle')時,只有7c61ad4612246177aec1482cc8266012Middle 45a2772a6b6107b401db3c9b82c049c2Text54bdf357c58b8a65c66d7c19c8e4d11494b3e26ee717c64999d7867364b1b4a3符合結果。

繼續對上述操作執行

end(),則filter()所產生的作用被撤銷,結果集中包含三個e388a4556c0f65e1904146cc1a846bee

以上是jQuery中end方法的用法的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn