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

jQuery中end方法的用法

巴扎黑
巴扎黑原创
2017-06-24 11:14:512252浏览

我们在对结果集使用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, includingadd(), andSelf(), children(), closes(), filter(), find(), map(), next(), nextAll(), not(), parent(), parents(), prev(), prevAll(), siblings(), slice(), clone(), appendTo(), prependTo(), insert<a href="http://www.php.cn/java/java-Before.html" target="_blank">Before</a>(), insertAfter(), replaceAll()

具体用法如下

<!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')时,只有d2a7bc930c02f9898ebf433876148125Middle 45a2772a6b6107b401db3c9b82c049c2Text54bdf357c58b8a65c66d7c19c8e4d11494b3e26ee717c64999d7867364b1b4a3符合结果。

继续对上述操作执行end(),则filter()产生的作用被撤销,结果集中包含三个e388a4556c0f65e1904146cc1a846bee

以上是jQuery中end方法的用法的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn