【问题标题】:clone content tag <template> in jQuery在 jQuery 中克隆内容标签 <template>
【发布时间】:2015-12-28 09:29:32
【问题描述】:

我正在尝试使用 jquery 克隆标签的内容,但我无法复制链接到子元素的事件, 我该怎么做?

【问题讨论】:

标签: javascript jquery templates clone


【解决方案1】:

您可以使用clone()方法,将withDataAndEventsdeepWithDataAndEvents参数都设置为true

var $templateClone = $('template').clone(true, true);

见:http://api.jquery.com/clone/

或者,您可以使用不带参数的普通 clone() 方法,并使用事件委托将您的事件绑定到一个公共父级。

【讨论】:

  • 当你这样使用时,它会复制所有模板标签,我想只复制标签的内容,附加到其他地方,我尝试使用:$('template'). children().clone(true, true);并且不复制任何元素
猜你喜欢
  • 2017-12-01
  • 2015-02-22
  • 1970-01-01
  • 1970-01-01
  • 2017-04-07
  • 2013-01-24
  • 2021-05-15
  • 1970-01-01
  • 2010-10-17
相关资源
最近更新 更多