gpt4 book ai didi

javascript - 保存数据Jquery后如何避免确认窗口?

转载 作者:太空宇宙 更新时间:2023-11-04 13:39:13 25 4
gpt4 key购买 nike

当我将卡片添加到收件箱时。然后可以双击卡片,弹出对话框。在对话框中,我有两个按钮(保存)和(取消)。当我按下取消按钮时,会弹出一个确认窗口。

我希望当我按下保存按钮时,按下取消按钮后,这个确认窗口不应该弹出。但是如果我没有保存数据,然后按下取消按钮,确认窗口应该会弹出。我自己尝试用 bool 值和 if 语句修复它,但没有成功。

我有一个 Demo

 // Double click to open Modal Dialog Window
$('#userAddedCard').dblclick(function (e) {
$currentTarget = $(e.target);

$('#modalDialog').dialog({
modal: true,
height: 600,
width: 500,
position: 'center',
buttons: {
Save: function () { //submit

save(true);

},
Cancel: function () { //cancel

cancel(true);

}

}
});

});

function save() {

var val = $("#customTextBox").val();
$currentTarget.find(".ctb").val(val);
$currentTarget.find(".date").val($("#datepicker").val());

}

function cancel() {

$('#dialog-confirm').dialog({
resizable: false,
height: 300,
modal: true,
draggable: false,
buttons: {
YES: function () {
$(this).dialog("close");
$('#modalDialog').dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});
}

最佳答案

使用 bool 值

// Double click to open Modal Dialog Window
$('#userAddedCard').dblclick(function (e) {
$currentTarget = $(e.target);

$('#modalDialog').dialog({
modal: true,
height: 600,
width: 500,
position: 'center',
buttons: {
Save: function () { //submit

save(true);

},
Cancel: function () { //cancel

cancel(true);

}

}
});

});
var boolean = false;
function save() {

var val = $("#customTextBox").val();
$currentTarget.find(".ctb").val(val);
$currentTarget.find(".date").val($("#datepicker").val());
boolean = true;

}

function cancel() {

if(!boolean){
$('#dialog-confirm').dialog({
resizable: false,
height: 300,
modal: true,
draggable: false,
buttons: {
YES: function () {
$(this).dialog("close");
$('#modalDialog').dialog("close");
},
Cancel: function () {
$(this).dialog("close");
}
}
});

}
else{
$('#dialog-confirm').hide();
}
}

当您点击取消时它会显示弹出窗口,当您在保存后点击它时点击保存按钮它会隐藏。

关于javascript - 保存数据Jquery后如何避免确认窗口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22814054/

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