看手册不太懂,谁能解释一下?
jquery ui里面的一个例子用到 end():
http://jqueryui.com/demos/sortable/portlets.html就这个例子说明一下:<script type="text/javascript">
$(function() {
$(".column").sortable({
connectWith: '.column'
}); $(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all")
.find(".portlet-header")
.addClass("ui-widget-header ui-corner-all")
.prepend('<span class="ui-icon ui-icon-plusthick"></span>')
.end()     //end 在这里
.find(".portlet-content"); $(".portlet-header .ui-icon").click(function() {
$(this).toggleClass("ui-icon-minusthick");
$(this).parents(".portlet:first").find(".portlet-content").toggle();
}); $(".column").disableSelection();
});
</script>

解决方案 »

  1.   

    把你例子里重要的部分提出来:
    $(".portlet").find(".portlet-header").end()
    首先,$(".portlet")返回所有包含有class="portlet"的元素,
    然后,在find(".portlet-header")以后,这句的返回就是同时包含class="portlet portlet-header"的,使用end()以后,就退回前一次选择,返回的值又变成所有包含有class="portlet"的元素
    你可以用alert测试一下:
    alert($(".portlet").find(".portlet-header").end() == $(".portlet"))简单说就是在一次选择以后再次进行选择使返回值的内容改变以后,退回到上一次的选择,一般用在连写里面。
      

  2.   

    选取所有的p元素,查找并选取span子元素,然后再回过来选取p元素 HTML 代码:<p><span>Hello</span>,how are you?</p> 
    jQuery 代码:$("p").find("span").end() 
    结果:[ <p><span>Hello</span> how are you?</p> ] 
      

  3.   

    回到最近的一个"破坏性"操作之前。即,将匹配的元素列表变为前一次的状态。如果之前没有破坏性操作,则返回一个空集。所谓的"破坏性"就是指任何改变所匹配的jQuery元素的操作。这包括在 Traversing 中任何返回一个jQuery对象的函数--'add', 'andSelf', 'children', 'filter', 'find', 'map', 'next', 'nextAll', 'not', 'parent', 'parents', 'prev', 'prevAll', 'siblings' and 'slice'--再加上 Manipulation 中的 'clone'。
      

  4.   

    找下jquery API文档看下不就得了。
      

  5.   

    HTML代码:
    <div></div><div></divJQ代码:
    $("<p/>")  //创建一个P元素
    .appendTo("div")  //添加到所有的div元素中
    .addClass("test")  //并添加class=test属性
    .end() //返回上一集再一次选择
    .addClass("test2");  //并添加class=test2属性结果:
    <div><p class="test test2"></p></div>
    <div><p class="test"></p></div>