首页 > jquery hover移到动态添加的区域,显示异常

jquery hover移到动态添加的区域,显示异常

$("#post-buy-table").find("tr:gt(0)").hover(function(){
    var $itemEditIcon = $("<td class='item-edit-icon'><span class='glyphicon glyphicon-edit'></span><span class='glyphicon glyphicon-trash'></span></td>");
    $(this).find("td:nth-child(3)").replaceWith($itemEditIcon);
},function () {
    $(this).find("td:nth-child(3)").replaceWith("<td></td>");
});


动态添加的元素用on去绑定事件

$("#post-buy-table").on("hover","tr",function(){
})

$("#post-buy-table").find("tr:gt(0)").hover(function(){
    var $itemEditIcon = $("<a href='#' class='glyphicon glyphicon-edit'></a><a href='#' class='glyphicon glyphicon-trash'></a>");
    $(this).find("td:nth-child(3)").append($itemEditIcon);
},function () {
    $(this).find("td:nth-child(3)").empty();
});

用这些代码写就正常了

【热门文章】
【热门文章】