---
title: "jQuery end()方法解释"
author: "pengfeng"
date: "2010-09-26T16:56:46Z"
tags: []
categories: ["Web前端"]
slug: "jquery-end"
draft: false
lastmod: "2010-09-26T16:56:46Z"
id: 772372
url: "https://pengfeng.iteye.com/blog/772372"
---

对于end()方法，jQuery文档是这样解释的：jQuery回到最近的一个"破坏性"操作

 

之前。即，将匹配的元素列表变为前一次的状态。

 

    但给的例子并不是很明显，相信不少人并没有理解它的用法。

 

    下边我们以一个非常简单的例子来说明下用法，html代码如下：

 

```
<div id="test">
    <h1>jQuery end()方法</h1>
    <p>讲解jQuery中end()方法。</p>
</div>
```

 

    下边是一小段jQuery代码：

 

```
$(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()方法。

 

*转自:http://hyipaying.com/article/jquery/20100915/jquery-end-method.html*