4

当我在数据不存在时对数据表执行鼠标悬停功能时,我收到错误“无法读取未定义的属性 '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];
    }
}
});

我应该做些什么检查,这样我就不会收到这个错误

谢谢

4

1 回答 1

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];
    }
  }
});
于 2013-08-16T09:04:26.303 回答