Javascript jQuery需要帮助在具有特定类的div元素中选择tr元素

Javascript jQuery需要帮助在具有特定类的div元素中选择tr元素,javascript,jquery,hover,jquery-hover,kendo-ui-grid,Javascript,Jquery,Hover,Jquery Hover,Kendo Ui Grid,我正在尝试使用剑道UI网格控件构建自定义悬停事件。在使用锁定列时,我无法在鼠标上方突出显示整行。我还没有找到一个简单的例子 当前悬停时的选择如下所示: 我编写了以下函数来尝试突出显示整行(锁定和解锁部分),但似乎无法获得正确的jQuery选择器: $("#ddhintgrid div.k-grid-content table tbody tr").hover(function () { //stuff to do on mouse enter var grid

我正在尝试使用剑道UI网格控件构建自定义悬停事件。在使用锁定列时,我无法在鼠标上方突出显示整行。我还没有找到一个简单的例子

当前悬停时的选择如下所示:

我编写了以下函数来尝试突出显示整行(锁定和解锁部分),但似乎无法获得正确的jQuery选择器:

$("#ddhintgrid div.k-grid-content table tbody tr").hover(function () {
        //stuff to do on mouse enter
        var grid = $("#ddhintgrid").data("kendoGrid");
        var rowUid = grid.dataItem(this).uid;

            // select the row currently being edited
        $('[data-uid=' +rowUid + ']').addClass('k-state-hover');
    },
    function () {
        //stuff to do on mouse leave
        $("#ddhintgrid .k-state-hover").removeClass("k-state-hover");
    });
这个方法的内容并不重要。我只想在用户将鼠标移动到网格未锁定部分的一行上时触发它


我希望.hover()函数启动的元素是
下的tr元素,以便正确地对排序等产生影响。这必须在网格上的
数据绑定事件中完成,或者应该能够在客户端完成。我没有测试这些,但它应该工作

客户端绑定 您需要添加一个用于切换类的函数:

addHoverStyleToGridRow = function () {
    $("table.k-focusable tbody tr").hover(function() {
            $(this).toggleClass("k-state-hover");
        }
    );
};
然后在数据绑定中:

// this is where the hover effect function is bound to grid
$("#ddhintgrid").kendoGrid({ dataBound: addHoverStyleToGridRow });
服务器绑定 如果您使用的是服务器绑定的网格,那么:

$(document).ready(function() {
     $("#ddhintgrid").find("table.k-focusable tbody tr").hover(function() {
            $(this).toggleClass("k-state-hover");
        }
    );
});

为了正确地对排序等产生影响,这必须在网格上的
dataBound
事件中完成,或者应该能够在客户端完成。我没有测试这些,但它应该工作

客户端绑定 您需要添加一个用于切换类的函数:

addHoverStyleToGridRow = function () {
    $("table.k-focusable tbody tr").hover(function() {
            $(this).toggleClass("k-state-hover");
        }
    );
};
然后在数据绑定中:

// this is where the hover effect function is bound to grid
$("#ddhintgrid").kendoGrid({ dataBound: addHoverStyleToGridRow });
服务器绑定 如果您使用的是服务器绑定的网格,那么:

$(document).ready(function() {
     $("#ddhintgrid").find("table.k-focusable tbody tr").hover(function() {
            $(this).toggleClass("k-state-hover");
        }
    );
});

我通过修改此处找到的解决方案找到了答案:

我将以下代码添加到网格数据源的dataBound函数中:

var $trs = $('table.k-selectable tbody tr');
$trs.hover(
    function () {
        var i = $(this).index() +1;
        $trs.filter(':nth-child(' +i + ')').addClass('k-state-hover');
    },
    function () {
        var i = $(this).index() +1;
        $trs.filter(':nth-child(' +i + ')').removeClass('k-state-hover');
    }
);

希望这能帮助其他有这个问题的人。尚未注意到任何问题。

我通过修改此处找到的解决方案找到了答案:

我将以下代码添加到网格数据源的dataBound函数中:

var $trs = $('table.k-selectable tbody tr');
$trs.hover(
    function () {
        var i = $(this).index() +1;
        $trs.filter(':nth-child(' +i + ')').addClass('k-state-hover');
    },
    function () {
        var i = $(this).index() +1;
        $trs.filter(':nth-child(' +i + ')').removeClass('k-state-hover');
    }
);
希望这能帮助其他有这个问题的人。还没有注意到任何问题。

试试看

$(“#ddhintgrid>.k-grid-content>table>tbody>tr:not(:first,:last)”).hover(函数(){…})试试看


$(“#ddhintgrid>.k-grid-content>table>tbody>tr:not(:first,:last)”).hover(函数(){…})dataBound:function(){$('.hover').hover(函数(e){hover($(this),e);});}
将函数放在dataBound参数中是我修复它的方法<代码>数据绑定:function(){$('.hover').hover(函数(e){hover($(this),e);});}