Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery突出显示ajax加载表中的一行_Javascript_Jquery_Html_Css_Ajax - Fatal编程技术网

Javascript JQuery突出显示ajax加载表中的一行

Javascript JQuery突出显示ajax加载表中的一行,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,一个页面包含两个表。第一个表与整个页面一起加载,第二个表随后在ajax的帮助下加载。 两个表的每一行都包含链接。 单击链接后,应突出显示相应的表行(链接所在的位置) 第一张桌子没有问题。以下工作正常: $(document).ready(function () { $('#firstTable tr a').click(function (event) { $('#firstTable tr').css("background

一个页面包含两个表。第一个表与整个页面一起加载,第二个表随后在ajax的帮助下加载。
两个表的每一行都包含链接。
单击链接后,应突出显示相应的表行(链接所在的位置)

第一张桌子没有问题。以下工作正常:

$(document).ready(function () {
        $('#firstTable tr a').click(function (event) {               
            $('#firstTable tr').css("background-color", "white");
            $(this).closest('tr').css("background-color", "silver");
        });
    });
但是第二张桌子有问题。我尝试使用
.live()
方法,但没有成功,它不会对单击做出反应:

function onLoad() {
              $('#secondTable tr a').live('click', function () {
                  highlChooseRow();
              });
          }

          function highlChooseRow() {
              $('#secondTable tr').css("background-color", "white");
              $(this).closest('tr').css("background-color", "silver");
          }
我做错了什么?

怎么样

$(document).ready(function () {
    $('#firstTable tr a, #secondTable tr a').live('click', function (event) {               
        $(this).parent('table').find('tr').css("background-color", "white");
        $(this).closest('tr').css("background-color", "silver");
    });
});
应该工作没有任何问题。对于清理,您还可以定义一些类“.highlightable table”或类似的类,并使用
$(“.hightlightable table a”).live