在您提供的链接页面中,有许多关于使用“单选”操作的解释。
在列出的附件末尾,您可以看到所引用的.js文件。
https://cdn.datatables.net/select/1.2.5/js/dataTables.select.min.js
在您的页面中,应在 dataTable.js 之后添加此文件引用。
我认为,jquery 的版本并不重要。重要的文件是 "dataTables.select.js"!
其次,您必须更新您的 dataTable 制作代码,如下面的示例所示;
$(document).ready(function() {
$('#example').DataTable( {
columnDefs: [ {
orderable: false,
className: 'select-checkbox',
targets: 0
} ],
select: {
style: 'os',
selector: 'td:first-child'
},
order: [[ 1, 'asc' ]]
} );
} );
更新:
为什么不尝试编写自己的选择器函数呢?
例如:
$(document).ready(function() {
$('#example').DataTable( {
} );
$('#example').find("tr").click(function(){ CheckTheRow(this); });
} );
function CheckTheRow(tr){
if($(tr).find("td:first").hasClass("selected")) return;
var activePaginationSelected = $("#example_length").find("select").val();
$("#example_length").find("select").val(-1).trigger("change");
$("#example").find("tr").each(function(i,a){
$(a).find("td:first").removeClass("selected");
$(a).find("td:first").html("");
});
$(tr).find("td:first").addClass("selected");
$(tr).find("td:first").html("<i class='fa fa-check'></i>");
$("#example_length").find("select")
.val(activePaginationSelected).trigger("change");
}