在jquery数据表中,如果表头包含名称为“ URL”的列,请为该表列数据提供超链接。我无法为此编写逻辑。请帮忙。
$(document).ready(function(){
var index = $('th:contains("Mar")').eq(0).index();
$("tr").each(function(rowIndex, row){
$(row).find("th:eq(" + index + ")").css('background', 'green');
$(row).find("td:eq(" + index + ")").html('<a href="index">+index+'</a>');
});
});
我已经尝试了上面的代码,但是我想让网址包含动态数据
答案 0 :(得分:2)
您可以使用jquery数据表渲染示例
var table = $('#example').DataTable({
columnDefs: [{
targets: 5,
render: function (data, type, full, meta) {
console.log(data);
if (data.indexOf("partofyourlink") >-1) {
return '<a href="http://somelink' + data + '.jpg">' + data + '</a>';
} else {
return data;
}
}
}]
});
您可以看看here
答案 1 :(得分:0)
尝试一下:
'columns':[{
'data': //your url data from json,
render: function(data, type, row) {
return '<a href= "'+ data +'"></a>"
}
}]