数据表 - 鼠标悬停时突出显示行
Datatables - highlight row on mouseover
我尝试在某个值出错时突出显示一行,但它在鼠标悬停时突出显示每一行。
我的错误在哪里?
https://jsfiddle.net/p0np06mx/
$('#table1').DataTable( {
"bFilter" : false,
"ordering": true,
columnDefs: [{
orderable: false,
targets: "no-sort"}],
"paging": false,
drawCallback: function (settings) {
$('#table1 tr').each(function () {
var Cell = $(this).find('td:eq(3)');
debugger;
if (Cell.text() !== 'error') {
$(this).find('button').hide();
$(this).find('textarea').hide();
}else{
$(this).parent().on('mouseover', 'tr', function() {
$(this).css('background-color', '#ff6900');
$(this).bind("mouseout", function(){
$(this).css('background-color', '');
});
});
}
});
}
您应该 运行 在鼠标悬停时查询。现在,您 运行 单元格在绘制 table.
后立即查询
fiddle ,只需替换
$(this)
和
cell
您确保指向正确的元素
我尝试在某个值出错时突出显示一行,但它在鼠标悬停时突出显示每一行。
我的错误在哪里?
https://jsfiddle.net/p0np06mx/
$('#table1').DataTable( {
"bFilter" : false,
"ordering": true,
columnDefs: [{
orderable: false,
targets: "no-sort"}],
"paging": false,
drawCallback: function (settings) {
$('#table1 tr').each(function () {
var Cell = $(this).find('td:eq(3)');
debugger;
if (Cell.text() !== 'error') {
$(this).find('button').hide();
$(this).find('textarea').hide();
}else{
$(this).parent().on('mouseover', 'tr', function() {
$(this).css('background-color', '#ff6900');
$(this).bind("mouseout", function(){
$(this).css('background-color', '');
});
});
}
});
}
您应该 运行 在鼠标悬停时查询。现在,您 运行 单元格在绘制 table.
后立即查询fiddle ,只需替换
$(this)
和
cell
您确保指向正确的元素