关于 jquery 克隆元素的快速问题。很长一段时间,我认为我必须在插入它(到 DOM 树)后重新 jqueryfy 克隆元素,但下面的代码工作正常。
HTML
<div id="test">test<"/div>
<button id="btn">push</div>
JavaScript
var $clone = $('#test').clone(),
$btn = $('#btn');
$clone.prop('id','clone').appendTo('body');
// I thought this is necessary but it's not.
// var $clone = $('#clone');
$btn.on('click',function(){
$clone.toggleClass('someclass');
});
那么有人可以告诉我为什么吗?