【发布时间】:2023-03-28 23:45:01
【问题描述】:
在我的 JQuery 数据表上添加删除确认时遇到问题。我的删除按钮上有一个单击方法,该方法调用有效的确认脚本,但是,如果我单击取消,则只有在单击“确定”时才应删除该行。
<script type="text/javascript">
var assetListVM;
$(function () {
assetListVM = {
dt: null,
init: function () {
dt = $('#file_list').DataTable({
"serverSide": true,
"processing": true,
"ajax": {
"url": "@Url.Action("GetFiles","AttachmentsUser")",
"data": function (d) {
d.s = $('input[type=search]').val();
}
},
"columns": [
{ "title": "FileName", "data": "file_name", "searchable": true },
{
"title": "Actions",
"data": "file_name",
"searchable": false,
"sortable": false,
"render": function (data, type, full, meta) {
return '<a href="@Url.Action("Download","AttachmentsUser")?file=' + data + '" class="download">Download</a> | <a href="@Url.Action("Delete","AttachmentsUser")?file=' + data + '" class="delete" onclick="DeleteFunction()">Delete</a>';
}
}
],
});
},
refresh: function () {
dt.ajax.reload();
}
}
$('body').on('keyup', 'input[type=search]', function () {
assetListVM.refresh();
});
// initialize the datatables
assetListVM.init();
});
</script>
<script>
function DeleteFunction() {
if (confirm('Are you sure you want to delete this user - have you removed all roles for this user?'))
return true;
else {
return false;
}
}
</script>
【问题讨论】:
标签: javascript asp.net-mvc datatables