我有一个表行,它是从父级克隆的。
这是代码:
$(this).closest("tr").clone(true).off().attr("class", "newclass").appendTo("#comparelist");
并且我还添加了以下代码:
$(".newclass").hover(function () {
alert("hello");
});
表格行已成功克隆,但无法触发悬停功能。
有谁知道为什么会这样吗?
谢谢你..
使用委托事件处理程序
$("#comparelist").on({
mouseenter : function () {
alert("mouse entered");
},
mouseleave : function () {
alert("mouse left");
}
}, ".newclass");
并删除 off()
var clone = $(this).closest("tr").clone(true);
clone.attr("class", "newclass");
clone.appendTo("#comparelist");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句