Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
jquery数据表在数组中推送td_Jquery_Datatable - Fatal编程技术网

jquery数据表在数组中推送td

jquery数据表在数组中推送td,jquery,datatable,Jquery,Datatable,我有数据表, 我想每次你点击tr时: 将tr中的所有td推送到javascript数组 它必须使用以下功能: 委派者,点击,功能 在这里输入代码 \$("#example tbody").delegate("tr", "click", function() { tablerow = ( \$( this ).text() ); 首先,在版本1.7中,委托被on取代。如果你没有使用至少1.10版,你应该升级它 其次,您可以使用映射从行中的td元素获取所有文本。试试这个: $('#exa

我有数据表, 我想每次你点击tr时: 将tr中的所有td推送到javascript数组

它必须使用以下功能: 委派者,点击,功能 在这里输入代码

\$("#example tbody").delegate("tr", "click", function() {
     tablerow = ( \$( this ).text() );
首先,在版本1.7中,委托被on取代。如果你没有使用至少1.10版,你应该升级它

其次,您可以使用映射从行中的td元素获取所有文本。试试这个:

$('#example tbody').on('click', 'tr', function() {
    var tdTextArray = $('td', this).map(function() {
        return $(this).text();
    }).get();
});
试试这个

var tablerow =[];
$("#example tbody").on("click", "tr", function() { // use on instead of delegate
    $(this).find('td').each(function(){ // grep all td
        tablerow.push($( this ).text()); // push td text to array
    });
});
阅读

您可以使用insert实现trs的唯一性,如


更好,让价值观​​将有所不同:\$example tbody.delegatetr,单击,函数{var myArray=[];//myArray.push\$this.text;//推送所有td文本\$this.find'td'。每个函数{myArray.push\$this.text;//将每个td文本推送到数组};tablerow=myArray[0];//alerttablerow;
var tablerow =[];
$("#example tbody").on("click", "tr", function() { // use on instead of delegate
    $(this).find('td').each(function(){ // grep all td
        tablerow.push($( this ).text()); // push td text to array
    });
});
var tablerow =[];
$("#example tbody").on("click", "tr", function(ind) { // use on instead of delegate
    var td=$(this).find('td').map(function(){ // grep all td
        return $( this ).text();
    }).get();
    tablerow.splice(ind, 0, td); // unique array for tr index
});