热门:网页模板.net视频教程JQueryMVCjsonExtJs源码示例三级联动JQuery菜单
您现在的位置:.Net中文社区>> AJAX编程>>正文内容

jquery中的 .end用法详解

发布时间:2011年04月12日点击数: 佚名
  1. $("img").clone().appendTo('#showOne').end().addClass('show'

jQuery提供了一个end()命令,在jQuery链内,一旦调用这个方法,方法就会作为返回值退回到前一个wraper.所以后续操作就会应用到前一个wraper.

也就是所.show加到了$("img")上。

又如:

  1. <script type="text/javascript"
  2. $(function() { 
  3. $(".column").sortable({ 
  4. connectWith: '.column' 
  5. }); 
  6.  
  7. $(".portlet").addClass("ui-widget ui-widget-content ui-helper-clearfix ui-corner-all"
  8. .find(".portlet-header"
  9. .addClass("ui-widget-header ui-corner-all"
  10.  .prepend('<span class="ui-icon ui-icon-plusthick"></span>'
  11.  .end() //end 在这里 
  12.    .find(".portlet-content"); 
  13.  
  14.  $(".portlet-header .ui-icon").click(function() { 
  15.  $(this).toggleClass("ui-icon-minusthick"); 
  16.  $(this).parents(".portlet:first").find(".portlet-content").toggle(); 
  17.  }); 
  18.  
  19.  $(".column").disableSelection(); 
  20.  }); 
  21.  </script> 

$(".portlet")返回所有包含有class="portlet"的元素,
然后,在find(".portlet-header")以 后,这句的返回就是同时包含class="portlet portlet-header"的,使用end()以后,就退回前一次选择,返回的值又变成所有包含有class="portlet"的元素,简单说就是 在一次选择以后再次进行选择使返回值的内容改变以后,退回到上一次的选择,一般用在连写里面。

本站热点业务

更多模板/案例展示

关于我们 | 联系我们 | 团队日志 | 网站地图 | 网站合作