Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/87.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/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
如何向jquery datatable中动态添加的行添加数据标题属性?_Jquery_Html_Css_Datatables - Fatal编程技术网

如何向jquery datatable中动态添加的行添加数据标题属性?

如何向jquery datatable中动态添加的行添加数据标题属性?,jquery,html,css,datatables,Jquery,Html,Css,Datatables,我在表中使用Datatable插件。我正在通过jQuery动态添加行: 代码: var t = $('#example').DataTable(); t.row.add( [ counter +'.1', counter +'.2', counter +'.3', counter +'.4', counter +'.5' ] ).draw(); 现在的问题是,我想让这个表具有响应性,因此更具体地说,我想使用jquery-like设置个人的属性 <

我在表中使用Datatable插件。我正在通过jQuery动态添加行:

代码:

var t = $('#example').DataTable();
 t.row.add( [
    counter +'.1',
    counter +'.2',
    counter +'.3',
    counter +'.4',
    counter +'.5'
] ).draw();
现在的问题是,我想让这个表具有响应性,因此更具体地说,我想使用jquery-like设置个人
的属性

<td data-title="counter1"> 
<td data-title="counter2" >
...and so on...

等等

是否有任何方法可以设置单个
的数据标题属性,该属性在单击datatable的按钮时动态添加

您可以为新添加的行获取
节点
容器节点对象,然后可以迭代其中的每个
来设置
数据标题
,如下所示:

var t = $('#example').DataTable();
var rowNode = t.row.add([
    counter +'.1',
    counter +'.2',
    counter +'.3',
    counter +'.4',
    counter +'.5'
]).draw()
.node(); //grab the container node

//find td present in this row
$( rowNode ).find("td").each(function(index){
    $(this).attr("data-title", "counter"+(index+1));
});

$(“td”).each(函数(索引,值){$(this.attr(“数据标题”,索引+1)});非常感谢……!:-)欢迎@Lalitkumar.annaldas。如果你愿意,你可以接受这个答案。