Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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更新表行的背景色_Javascript_Jquery_Html - Fatal编程技术网

Javascript 使用jquery更新表行的背景色

Javascript 使用jquery更新表行的背景色,javascript,jquery,html,Javascript,Jquery,Html,我使用以下jquery将外部html页面加载到名为content的div中: $(document).ready(function(){ $("#content").load("content.html"); }); (function($) { $(function() { $('.load_link').click(function() { $("#content").load("content2.html"); return false;

我使用以下jquery将外部html页面加载到名为content的div中:

$(document).ready(function(){
     $("#content").load("content.html");
});

(function($) {  
 $(function() {  
 $('.load_link').click(function() {  
    $("#content").load("content2.html");  
    return false;  
 });  
});  
})(jQuery); 

触发内容更改的链接(使用
)位于表中的一行内。我希望能够在有人单击链接时更新分配给表中某一行的类。包含所单击链接的行应分配类别“rowselected”,所有其他行(仅在该表中)应分配类别“rownotselected”。只有此表中的行使用这些类名,因此替换出现的任何类名都应该是安全的

这可能吗?我第一次使用jquery

提前感谢您的建议

那么:

 $('.load_link').click(function() {  
    $("#content").load("content2.html");  
    var $row = $(this).closest("tr");
    // find the parent <tr> and set the class
    $row.removeClass("rownotselected").addClass("rowselected");
    // Set the class of the other rows:
    $row.siblings("tr").removeClass("rowselected").addClass("rownotselected");
    return false;  
 }); 
$('.load_link')。单击(函数(){
$(“#content”).load(“content2.html”);
var$row=$(this.closest(“tr”);
//找到父对象并设置类
$row.removeClass(“rownotselected”).addClass(“rowselected”);
//设置其他行的类别:
$row.SIBLINES(“tr”).removeClass(“rowselected”).addClass(“rownotselected”);
返回false;
}); 
  • 使用查找父级
    tr
  • 使用
    removeClass
    addClass
    删除相应的类
  • 用于查找当前表中的同级行

下面是一个工作示例:

您是否也可以为要更新的表提供HTML?