jQuery 推送堆栈 [英] jQuery pushStack

查看:19
本文介绍了jQuery 推送堆栈的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些帮助来理解 pushStack

I need some help to understand pushStack

这里我做了一个例子,使用与否的结果是一样的http://jsfiddle.net/Bz5n9/2/ 所以我想我真的不明白它的用途.

Here I've made an example where the results using it or not are the same http://jsfiddle.net/Bz5n9/2/ so I think i really didn't get what is it for.

谢谢!

推荐答案

您当前正在添加到集合中,将一个新集合推送到堆栈上,该集合已经是结果(您可以只返回 this.添加()).它所做的不是将 .b 元素作为新元素推送到堆栈上,而是推送带有 .b 元素 的新集合#2 <li> 你开始用的.

You're currently adding to the collection, pushing a new collection on the stack that's already the result (you could just return the result of this.add()). What this does is instead of pushing .b elements on the stack as a new element, it pushes a new set with .b elements and the #2 <li> you started with.

相反,您应该直接传递元素(没有 .add() 调用),像这样:

Instead, you instead should pass the elements directly (no .add() call), like this:

return this.pushStack(newCollection, "agregate", "");

你可以在这里测试一下.

这篇关于jQuery 推送堆栈的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆