【发布时间】:2025-12-14 16:05:02
【问题描述】:
是否可以在数据表构建行时附加点击事件?无需调用外部全局函数并找到关闭 tr 并获取 DATA 对象。
$('#example').DataTable({
columns : [{
title : 'msg',
sClass : 'col-sm-2',
render : function(data, type, row){
var b = $('<button>the button</button>').click(function(){
alert(row.msg);
})
return b;
}
}],
ajax:{
type : 'POST',
url : 'foo.php',
}
});
我知道上面的例子dosnt工作,cos渲染函数必须返回字符串,它只是我需要的一个例子。
- 创建一个元素。
- 附加单击函数传递“行”对象,而不调用全局函数。
【问题讨论】:
标签: jquery datatables