我无法在JQuery数据表上添加删除确认。我的删除按钮上有一个on click方法,该方法调用有效的确认脚本,但是,如果单击“取消”,则仅当单击“确定”时才删除该行,该行将被删除。
<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>
答案 0 :(得分:1)
使用return
取消默认浏览器行为。
onclick="return DeleteFunction()"