api是这样说的:
clone(true)
元素以及其所有的事件处理并且选中这些克隆的副本 在想把DOM文档中元素的副本添加到其他位置时这个函数非常有用。
Clone matched DOM Elements, and all their event handlers, and select the clones. This is useful for moving copies of the elements, and their events, to another location in the DOM.
返回值
jQuery
参数
true(Boolean) : 设置为true以便复制元素的所有事件处理
示例
创建一个按钮,他可以复制自己,并且他的副本也有同样功能。
HTML 代码:
<button>Clone Me!</button>
jQuery 代码:
$("button").click(function(){
$(this).clone(true).insertAfter(this);//不带true的clone()不会克隆事件处理
});
通常用于动态加载本页面元素 查看DEMO
Comments(0)