看手册不太懂,谁能解释一下?
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>
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>
$(".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"))简单说就是在一次选择以后再次进行选择使返回值的内容改变以后,退回到上一次的选择,一般用在连写里面。
jQuery 代码:$("p").find("span").end()
结果:[ <p><span>Hello</span> how are you?</p> ]
<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>