jQuery highlighting selected columns only in a table

后端 未结 6 1102
长发绾君心
长发绾君心 2021-01-02 19:46

I see this post on highlighting even columns but can I highlight only selected columns?

Here is the code they use:

$(\"table.Table22 > tbody >          


        
6条回答
  •  死守一世寂寞
    2021-01-02 20:42

    Here's what I use for adding a cross-hair affect to my table:

    $('tbody td').hover(function() {
        $(this).closest('tr').find('td,th').addClass('highlight');
        var col = $(this).index()+1;
        $(this).closest('table').find('tr :nth-child('+col+')').addClass('highlight');
    }, function() {
        $(this).closest('tr').find('td,th').removeClass('highlight');
        var col = $(this).index()+1;
        $(this).closest('table').find('tr :nth-child('+col+')').removeClass('highlight');
    });
    

    Seems to run a bit slow on large tables though (the highlighting lags behind).

提交回复
热议问题