所以我有一个记录表,每个人都有一个删除按钮。我想添加一个确认弹出窗口,该弹出窗口将在按钮单击时显示。
var $confirmDialog = $('<div></div>')
.html('This record will be removed.')
.dialog({
autoOpen: false,
title: 'Remove confirtmation',
buttons: {
"OK": function () {
$(this).dialog("close");
return true;
},
"Cancel": function () {
$(this).dialog("close");
return false;
}
}
});
我的删除按钮事件:
$(".removeButton").on("click", function(){
if($confirmDialog.dialog('open')){
var name = $(this).siblings(".someClassForNameHolder").text();
var urlPath = $("#hiddenForUrl").val();
Application.postRecord(name, "Remove", urlPath);
}
});
顺便说一句,我几乎没有以下几点:
1)我无法在表中提供唯一ID的记录,因此我必须将数据收集(name
变量)保留在我的removeButton
事件中(以便能够使用this.sibling ...)。<<<<<<<<<<<<
2)我希望我的脚本等到 $confirmDialog
返回值,然后继续执行代码。
只需将您的urlPath
分配给全局变量,然后在OK
处理程序内执行POST
:
var nameToRemove, urlPathToRemove;
var $confirmDialog = $('<div></div>')
.html('This record will be removed.')
.dialog({
autoOpen: false,
title: 'Remove confirtmation',
buttons: {
"OK": function () {
$(this).dialog("close");
Application.postRecord(nameToRemove, "Remove", urlPathToRemove);
},
"Cancel": function () {
$(this).dialog("close");
return false;
}
}
});
$(".removeButton").on("click", function(){
if($confirmDialog.dialog('open')){
nameToRemove = $(this).siblings(".someClassForNameHolder").text();
urlPathToRemove= $("#hiddenForUrl").val();
}
});