Javascript JQuery突出显示ajax加载表中的一行
一个页面包含两个表。第一个表与整个页面一起加载,第二个表随后在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
两个表的每一行都包含链接。
单击链接后,应突出显示相应的表行(链接所在的位置) 第一张桌子没有问题。以下工作正常:
$(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