jquery活动条件不工作

jquery活动条件不工作,jquery,ajax,live,Jquery,Ajax,Live,我正在使用jquery,在正常情况下$(文档)。ready表中的行和列高亮显示。但当我使用$.ajax({})调用带有表的数据时,行和列不会突出显示 我的代码就是这样 $('table td').hover( function() { $(this).css('background-color','white'); $(this).siblings().css('background','#F0F8FF'); var ind = $(this).index();

我正在使用jquery,在正常情况下
$(文档)。ready
表中的行和列高亮显示。但当我使用
$.ajax({})
调用带有表的数据时,行和列不会突出显示

我的代码就是这样

$('table td').hover( function() {
     $(this).css('background-color','white'); 
     $(this).siblings().css('background','#F0F8FF'); 
     var ind = $(this).index(); 
     $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
}, function() { 
     $('table td').css('background','white');
}).click( function() { 
     $(this).css("background","#9DFF9D");
});
function HighlightTable(){
    //table hover column & row highlight    
    $('table td').hover(function() {
        $(this).css('background-color','white');
        $(this).siblings().css('background','#F0F8FF');
        var ind = $(this).index();
        $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
    },function(){
        $('table td').css('background','white');
    }).click(function(){$(this).css("background","#9DFF9D");});
}
有人知道解决办法吗

在实时代码中

$('table td').live("hover",function() {
        $(this).css('background-color','white');
        $(this).siblings().css('background','#F0F8FF');
        var ind = $(this).index();
        $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
    });
我找到了解决方案

我创建这样的函数

$('table td').hover( function() {
     $(this).css('background-color','white'); 
     $(this).siblings().css('background','#F0F8FF'); 
     var ind = $(this).index(); 
     $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
}, function() { 
     $('table td').css('background','white');
}).click( function() { 
     $(this).css("background","#9DFF9D");
});
function HighlightTable(){
    //table hover column & row highlight    
    $('table td').hover(function() {
        $(this).css('background-color','white');
        $(this).siblings().css('background','#F0F8FF');
        var ind = $(this).index();
        $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
    },function(){
        $('table td').css('background','white');
    }).click(function(){$(this).css("background","#9DFF9D");});
}
调用
$.ajax
时,请使用
HighlightTable()
onsuccess
条件

$.ajax({
   url:'something.php'
   success: function(data){
      $('div').html(data); HighlightTable();
   }
})
仅此而已,谢谢各位

我看不到
.live()
,而且首先您使用
背景色
,剩下的您只使用
背景色
。。这就是问题所在吗

$('table td').on("hover",function() {
    $(this).css('background-color','white');
    $(this).siblings().css('background','#F0F8FF');
    var ind = $(this).index();
    $('table td:nth-child('+(ind+1)+')').css('background','#F0F8FF');
});

检查此代码。

最好使用
.on()
事件委派
最近的现有父级
文档本身

$(document).on('hover', 'table td', function() {
     $(this).css('background-color','white'); 
     $(this).siblings().css('background','#F0F8FF'); 
     var ind = $(this).index(); 
     $('table td:nth-child('+Math.floor(ind+1)+')').css('background','#F0F8FF');
 }, function() { 
     $('table td').css('background','white');
 }).click( function() { 
     $(this).css("background","#9DFF9D");
 });
.hover()
有自己的处理程序:

如果要执行多项操作,请在
.on()
处理程序中链接它们,如下所示:

$(document).on(
{
    mouseenter: function() 
    {
        //stuff to do on mouseover
    },
    mouseleave: function()
    {
        //stuff to do on mouseleave
    }
}
, '.selector'); //pass the element as an argument to .on
jQuery支持
live()
事件的“悬停”,但只支持一个事件处理程序函数:

$("document").live("hover",
     function()
     {

     }
);
因此,您也可以提供两个函数,一个用于mouseenter,另一个用于mouseleave,正如我在上面所写的那样。

试试这个:

$(document).on({ 
    mouseenter: 
       function() 
       { 
       $(this).css('background-color', 'white');
       $(this).siblings().css('background-color', '#F0F8FF');
       var ind = $(this).index();
       $('table td:nth-child(' + (ind + 1) + ')').css('background-color', '#F0F8FF');
       }, 
    mouseleave: 
       function() 
       { 
       $('table td').css('background-color', 'white');
       } ,
    click:
       function() 
       { 
        $(this).css("background-color", "#9DFF9D");
       } ,
   }, "table td"
);

参见示例

use$('table td').live(“hover”,function(){live condition类似于这样的
$('table td').live(“mouseenter”,function(){$(this).css('background-color','white');$(this).sides().css('background','F0F8FF');var ind=$(this.index();$('table td:n子级('+(ind+1)+'))).css('background','F0F8FF'));
但结果并非如此expectation@jinSun表结构是必需的,如果您能够发布,请将其发布到您的帖子中。
$('table td').live(“mouseenter”,function(){$(this).css('background-color','white');$(this).sides().css('background','F0F8FF');var ind=$(this).index();$('table td:n child(+(ind 1)+')).css('background','F0F8FF');)
行和列是高位的,但不是很好。我试过你的代码,结果没有突出显示行和列,还有其他的吗?你能给出你的表结构吗?首先,我建议你使用@JinSun-answer,但我认为问题不是基于此。你能更新你的问题以包括你的HTML吗?另外,请注意sistent!如果您使用背景色,请在剩下的代码中也使用它。不要在第二行中使用背景色,在其他行中使用背景色。检查我编辑的代码,您想在hover上更改td的颜色,对吗?@DevangRathod它看起来很有希望,但您知道jQuery在()上支持live()的“hover”吗只有一个事件处理函数的事件…??是的,我也这样做,但仍然不如ExpExtationin好,因为它在live Condition之前是不同的。这不是一个坏主意,但仍然不像预期的那样。在不live时仍然不同condition@JinSun:为什么要调用
HighlightTable()
function.???!!!鼠标悬停和单击事件只需位于
$(文档)中即可。就绪({});
…不需要像示例代码中那样的函数…我以前做过,但它不起作用。我的方法很好用。你应该试试