我有一个HTML图像元素,如下所示:克隆HTML元素与活动
var actionImage = $("<img></img>");
actionImage.attr("id", getRandomString());
actionImage.attr("width", "16").attr("height", "16").attr("src", "Action_normal.png");
actionImage.attr("style", "cursor: hand;");
actionImage.bind('mouseover', function() {
OnMouseOver($(this).get(0));
});
当我克隆该元件I松开鼠标悬停事件。我怎样才能确保这些事件也被克隆。
'$(this).get(0)'是错误的。这与完成“this”完全相同。尝试:'alert($(this).get(0)=== this); // true' – 2012-02-17 23:23:39
您也可以考虑通过传递一个对象来设置属性,从而将5'.attr()'调用减少为只有一个。 'actionImage.attr({id:getRandomString(),width:16,height:16 ...})' – 2012-02-17 23:27:57