对于end()方法,jQuery文档是这样解释的:jQuery回到最近的一个"破坏性"操作
之前。即,将匹配的元素列表变为前一次的状态。
- <div
id="test"> -
<h1>jQuery end()方法</h1> -
<p>讲解jQuery中end()方法。</p> - </div>
JS代码:
- $(document).ready(function()
{ -
$("#test").click(function() { -
$(this).find("p").hide().end().hide(); -
}); - });
点击id为test的div时,首先找到div里边的p标签,将其隐藏。接下来使用end()
方法结束了对p标签的引用,此时返回的是#test(jQuery对象),从而后边的hide()方法
隐藏了div。这样相信大家已经理解了jQuery中end()方法。