【发布时间】:2019-07-18 11:44:40
【问题描述】:
我有一个 DataTable,我在其中显示 API 中的所有值。现在我有一个 Detail 列,其中有一个带删除按钮的 href 标记。我想添加一个类名或 id,但它会引发错误。这是example。
我想获取行值并删除数据。你能帮我解决这个问题吗?
HTML:
<table id="example" class="display" cellspacing="0" width="100%">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Subject</th>
<th>Message</th>
<th>Details</th>
</tr>
</thead>
</table>
脚本:
$(document).ready(function() {
$('#example').DataTable({
"processing" : true,
"ajax" : {
"url" : "https://api.myjson.com/bins/un18a",
dataSrc : ''
},
"columns" : [ {
"data" : "name"
}, {
"data" : "email"
}, {
"data" : "subject"
}, {
"data" : "message"
},
{
"mData": "Details",
"mRender": function (data, type, row) {
return "<a id="delete" href='/Details/" + row.id + "'>Delete</a>";
}
}]
});
});
【问题讨论】:
标签: javascript jquery html datatables bootstrap-4