带有新 ID 的 jQuery .clone .insertAfter
如何克隆 DIV,将其附加到 div 之后并为其指定新的标识符?
我有一个带有类 reflection
的 DIV,我希望克隆该 DIV 的每个实例,并将其插入到原始 DIV 之后,但带有类 reflected
(没有类, reflection
) 我怎样才能用 jQuery 完成这个任务?
这是我当前的小提琴,但它无法正常工作... http://jsfiddle.net/yUgn9/
How can I clone a DIV, append it right after the div and give it a new identifier?
I have a DIV with a class reflection
, I want each instance of this DIV, cloned, and inserted right after the original, but with the class reflected
(without the class, reflection
) How can I accomplish this with jQuery?
Here's my current fiddle, but it doesn't work right... http://jsfiddle.net/yUgn9/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将函数传递给
.after()
,并让它返回更新后的克隆。演示: http://jsfiddle.net/PFBVX/
在旧版本的 jQuery 中,执行此操作...
演示: http://jsfiddle.net/PFBVX/1/
Pass a function to
.after()
, and have it return the updated clone.DEMO: http://jsfiddle.net/PFBVX/
In older versions of jQuery, do this...
DEMO: http://jsfiddle.net/PFBVX/1/
我相信您需要 .each() 来单独处理它们。代码当前所做的就是获取所有这些并在所有这些之后克隆它们。相反,您希望单独处理每个类,并在根据需要更改类之后将克隆插入到原始类之后。
I believe you'll need to .each() of them to handle them individually. What the code is currently doing is grabbing all of them and cloning them after all of them. Instead, you want to handle each of them individually and insert the clone after the original, after changing the classes around as desired.