相关疑难解决方法(0)

将TR移动到另一个表后,jquery hover()和click()不起作用

我正在尝试使用jQuery的hover()来更改鼠标悬停的任何TR的背景颜色,并且我还使用click()在表之间移动TR.但是一旦我将TR移动到另一个表,hover()和click()就不起作用了.

有人可以告诉我为什么吗?我怎么解决这个问题?这是我的代码:http://jsfiddle.net/MJNGL/

$(document).ready(function() {
    $("table tr").hover(
        function() {
            $(this).css('background', 'yellow');
        },
        function () {
            $(this).css('background', '');
        }
    )

    $("table tr").click(function () {
        var id = $(this).children().attr("id");
        $(".cityItem1").each(function m(x,e) {
            if ($(e).children().attr("id") == id) {
                $(e).remove();
                $("#tblCity2").append('<tr class="tableRow"><td width="750" id="' + $(e).children().attr('id') + '">' + $(e).children().html() + '</td></tr>');
            }
        });
    });
});
?
Run Code Online (Sandbox Code Playgroud)

jquery

1
推荐指数
1
解决办法
1590
查看次数

标签 统计

jquery ×1