下面是我一直在处理的索引页面的 html。我想编辑和删除数据表中的按钮,但不起作用


<script>
$(document).ready(function () {  
// New record
$('#MyTable').on('click', 'a.editor_create', function (e) {
e.preventDefault();
editor.create({
title: 'Create new record',
buttons: 'Add'
});
});
// Edit record
$('#MyTable').on('click', 'a.editor_edit', function (e) {
e.preventDefault();
editor.edit($(this).closest('tr'), {
title: 'Edit record',
buttons: 'Update'
});
});
// Delete a record
$('#MyTable').on('click', 'a.editor_remove', function (e) {
e.preventDefault();
editor.remove($(this).closest('tr'), {
title: 'Delete record',
message: 'Are you sure you wish to remove this record?',
buttons: 'Delete'
});
});
$('#MyTable').DataTable( {  
"processing": true,
"crossDomain": true,
"ajax": {
"url": "https://jsonplaceholder.typicode.com/comments",
"dataType": "jsonp",
"dataSrc":""
},
"columns": [
{ "data": "id" },
{ "data": "name" },
{ "data": "email" },
{ "data": "body" }, 
{
data: null,
className: "center",
defaultContent: '<a href="" class="editor_edit"onclick="editor_edit()">Edit</a> / <a href="" class="editor_remove">Delete</a>'
}

]
} );  
} );  

</script>

试试这个。

$('body').on('click', 'a.editor_edit', function() {
// do something
});

最新更新