jQuery .clone() .html() in IE Bug

微笑、不失礼 提交于 2019-12-01 06:46:17

问题


There seems to be a bug still present in jQuery 1.6.2 that has an issue with .clone() and .html(). I created a fiddle: http://jsfiddle.net/Vxyu3/12/ that should help explain the bug. If you click on both links one after another, in Firefox the content will flip back and forth with no problems. In IE however (particularly IE7) if you go to the fiddle and then hit "Show Dynamic Content" then "Show Clone" then "Show Dynamic Content" then "Show Clone", the clone content is no longer visible. In fact it's not even injected into the DOM. It's like it disappears, or get erased somewhere along the way... Has anyone come across this bug and where I would start about fixing the issue.

Thanks!

http://jsfiddle.net/Vxyu3/12/


回答1:


May be a closure reference bug. Try defining the cloned parameter in global scope, but keep the assignment within the ready callback.

No, that doesn't work. It looks like a jQuery/IE bug where using a jQuery object for the HTML() function causes some problems.

Try this instead: domCloneMe.html(cloned.html());




回答2:


Had to get around this by throwing the cloned object into a another div, hiding that div, and then appending its contents each time. Annoying and makes for longer code, but it's about the only thing that works right now.



来源:https://stackoverflow.com/questions/7243384/jquery-clone-html-in-ie-bug

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!