gpt4 book ai didi

javascript - JQuery 数据表确认删除行

转载 作者:行者123 更新时间:2023-11-30 19:34:45 25 4
gpt4 key购买 nike

我无法在我的 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>

最佳答案

使用 return 取消默认的浏览器行为。

onclick="return DeleteFunction()"

关于javascript - JQuery 数据表确认删除行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56058490/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com