Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.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
jQuery:选择当前行上方的特定最近/同级行_Jquery_Selector_Traversal_Closest_Siblings - Fatal编程技术网

jQuery:选择当前行上方的特定最近/同级行

jQuery:选择当前行上方的特定最近/同级行,jquery,selector,traversal,closest,siblings,Jquery,Selector,Traversal,Closest,Siblings,当鼠标在C、D、E&F(图1高亮显示)和K&L(图3高亮显示)上移动时,必须更改哪些内容以使“img”类TD单元格也高亮显示?不仅仅是在定义了“行跨度”的“第一行”(A、B、G、H&J)上 jQuery $(document).ready(function(){ $(".stripeMe tr").mouseover(function() { $(this).addClass("over");}).mouseout(function(){ $(t

当鼠标在C、D、E&F(图1高亮显示)和K&L(图3高亮显示)上移动时,必须更改哪些内容以使“img”类TD单元格也高亮显示?不仅仅是在定义了“行跨度”的“第一行”(A、B、G、H&J)上

jQuery

$(document).ready(function(){
     $(".stripeMe tr").mouseover(function() {
        $(this).addClass("over");}).mouseout(function(){
            $(this).removeClass("over");});
});
要尝试的代码示例:

试试这个

$(document).ready(function(){
  $(".stripeMe").delegate("td", "mouseover", function() {
     if($(this).closest("tr").hasClass("row1")){
        $(this).closest("tr").find(".img").addClass("over");
     } 
     else{
         var tr =  $(this).closest("tr");
         while(!tr.hasClass("row1")){
            tr =  tr.prev("tr");   
         }       
         tr.find(".img").addClass("over");                   
     }

 })
 .delegate("td", "mouseout", function(){
        $(this).closest(".stripeMe").find(".img").removeClass("over");
 });
});
试试这个

$(document).ready(function(){
  $(".stripeMe").delegate("td", "mouseover", function() {
     if($(this).closest("tr").hasClass("row1")){
        $(this).closest("tr").find(".img").addClass("over");
     } 
     else{
         var tr =  $(this).closest("tr");
         while(!tr.hasClass("row1")){
            tr =  tr.prev("tr");   
         }       
         tr.find(".img").addClass("over");                   
     }

 })
 .delegate("td", "mouseout", function(){
        $(this).closest(".stripeMe").find(".img").removeClass("over");
 });
});

谢谢你的回答,但这不是我所期望的。。。看这里,你的代码的结果是什么:也许我不太清楚我想要实现什么:我想在所有的行A..L上用鼠标突出显示相应的图1..3,就像它在“第一行”(A,B,G,H&J)上所做的那样@Billy-你到底需要什么?我以前是禁食的。我对你的问题的回答在上面,在我的评论中。我签入了JSFIDLE,我的回答与你在问题中提到的完全一样。@Billy-请检查我编辑的答案,它现在按照你的预期工作[谢谢你的回答,但这并不是我所期望的…看这里,你的代码的结果是什么:也许我不太清楚我想要实现什么:我想用鼠标在所有行A..L上突出显示相应的图1..3,就像它在“第一行”(A、B、G、H&J)上那样)@比利-你到底需要什么?我以前是要禁食的。我对你的问题的答案在上面,在我的评论中。我在JSFIDLE上签了名,我的答案完全符合你在问题中提到的要求。@比利-请检查我编辑的答案,它现在按照你的预期工作[
$(document).ready(function(){
  $(".stripeMe").delegate("td", "mouseover", function() {
     if($(this).closest("tr").hasClass("row1")){
        $(this).closest("tr").find(".img").addClass("over");
     } 
     else{
         var tr =  $(this).closest("tr");
         while(!tr.hasClass("row1")){
            tr =  tr.prev("tr");   
         }       
         tr.find(".img").addClass("over");                   
     }

 })
 .delegate("td", "mouseout", function(){
        $(this).closest(".stripeMe").find(".img").removeClass("over");
 });
});