Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript DataTables:获取选定单元格之前单元格的文本内容_Javascript_Jquery_Datatables - Fatal编程技术网

Javascript DataTables:获取选定单元格之前单元格的文本内容

Javascript DataTables:获取选定单元格之前单元格的文本内容,javascript,jquery,datatables,Javascript,Jquery,Datatables,我可以按如下方式获取选定的单元格文本内容: this.textContent 但我想在选定单元格之前获取单元格的文本内容。我该怎么做?。我试过这样做,但它说未定义: $('#dtBasicExample').on('click', 'tbody td', function() { var table = $('#dtBasicExample').DataTable(); var colIndex = table.cell(this).index().column-1;//get p

我可以按如下方式获取选定的单元格文本内容:

this.textContent

但我想在选定单元格之前获取单元格的文本内容。我该怎么做?。我试过这样做,但它说
未定义

$('#dtBasicExample').on('click', 'tbody td', function() {

  var table = $('#dtBasicExample').DataTable();


  var colIndex = table.cell(this).index().column-1;//get previous column index
  var rowIndex = table.cell(this).index().row;//get row index

  var Text=table.cells(rowIndex, colIndex).textContent;//get textContent(not working)

    alert(Text);
})
使用
table.cells(rowIndex,colIndex).data()
代替
table.cells(rowIndex,colIndex).textContent

var table = $('#dtBasicExample').DataTable();

$('#dtBasicExample').on('click', 'tbody td', function () {

    var colIndex = table.cell(this).index().column - 1; //get previous column index
    var rowIndex = table.cell(this).index().row; //get row index

    // Use data() instead of textContent and cell instead of cells
    var text = table.cell(rowIndex, colIndex).data(); 

    alert(text);
});
使用
table.cells(rowIndex,colIndex).data()
代替
table.cells(rowIndex,colIndex).textContent

var table = $('#dtBasicExample').DataTable();

$('#dtBasicExample').on('click', 'tbody td', function () {

    var colIndex = table.cell(this).index().column - 1; //get previous column index
    var rowIndex = table.cell(this).index().row; //get row index

    // Use data() instead of textContent and cell instead of cells
    var text = table.cell(rowIndex, colIndex).data(); 

    alert(text);
});

Datatable检查触发元素的Jquery对象内的
\u DT\u CellIndex
属性,以确定列和行

我们可以在用Datatable加载它之前简单地修改_DT_CellIndex

示例代码:

$('#示例')。在('click','td',function()上{
var table=$(this).closest('table').DataTable();
$(此)[0]。\u DT\u CellIndex.column-=1;
警报(table.cell($(this)).data());
});

名称
位置
办公室
头号人物
开始日期
薪水
老虎尼克松
系统架构师
爱丁堡
155555
2011/04/25
$320,800
加勒特温特斯
会计
东京
63
2011/07/25
$170,750
阿什顿考克斯
初级技术作者
旧金山
1.
2009/01/12
$86,000
阿什顿考克斯
初级技术作者
旧金山
1.
2009/01/12
$86,000

数据表检查
\u DT\u CellIndex
触发元素的Jquery对象内的属性,以确定列和行

我们可以在用Datatable加载它之前简单地修改_DT_CellIndex

示例代码:

$('#示例')。在('click','td',function()上{
var table=$(this).closest('table').DataTable();
$(此)[0]。\u DT\u CellIndex.column-=1;
警报(table.cell($(this)).data());
});

名称
位置
办公室
头号人物
开始日期
薪水
老虎尼克松
系统架构师
爱丁堡
155555
2011/04/25
$320,800
加勒特温特斯
会计
东京
63
2011/07/25
$170,750
阿什顿考克斯
初级技术作者
旧金山
1.
2009/01/12
$86,000
阿什顿考克斯
初级技术作者
旧金山
1.
2009/01/12
$86,000