当数据不存在时,当我在数据表上执行鼠标悬停功能时,我收到错误“无法读取未定义的属性'ntr'。填充表时,它工作正常。 代码如下:
$('#example_table tbody td').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {// do something on mouseover
console.log('inside mouseover');
var iPos = oTable.fnGetPosition( this ); // getting error in this line
if(iPos!=null){
console.log(iPos);
var iCol= iPos [1];
}
}
});
我应该做什么检查,以免我收到此错误
由于
答案 0 :(得分:1)
您可以检查您的表是否已填充,如果未填充:
$('#example_table tbody td').live('mouseover mouseout', function(event) {
if (event.type == 'mouseover') {// do something on mouseover
console.log('inside mouseover');
// check if you have data in your table
if (oTable.fnGetData().length <= 0) { // or some similar check
return;
}
var iPos = oTable.fnGetPosition( this ); // getting error in this line
if(iPos!=null){
console.log(iPos);
var iCol= iPos [1];
}
}
});