jquery gurus, jquery extend is not cloning the dom elements

北战南征 提交于 2019-12-13 01:50:48

问题


Here is the jsfiddel:

class Overlay
    constructor: ->
      @header = $("<div> header</div>")
      @footer = $("<div> footer</div>")      
    get: ->
      @popup = $("<div></div>").append(@header).append(@footer)
      @popup.clone(true)

overlay = new Overlay
overlay_extend = {}    
$.extend(true,overlay_extend,overlay)
overlay_extend.header.append("<div>more header</div>")  
overlay.header.appendTo("body")

In the jsfiddle I changed the extended dom element and the orginal dom is changed..Any new ideas.


回答1:


extend only clones native JS objects, not DOM elements. Here, the cloned jQuery object still points to the original DOM element.

You need to .clone() the DOM elements.



来源:https://stackoverflow.com/questions/9639836/jquery-gurus-jquery-extend-is-not-cloning-the-dom-elements

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