0
我一直坚持这几天。我使用的是sweetalert2,我试图完成的是根据给定的答案触发一个javascript函数,所以如果我点击确定,它会触发一件事,如果我点击取消,它会执行其他操作。我可以让它工作,但它似乎在甜蜜警报完成之前触发该功能。这里是一个代码示例:响应甜蜜提示2后触发一个函数
<script>
function validateSubmit(a,b,c){
var mode = a;
var info = b;
var trunk = c;
var iteration = baseName(info);
if (mode === 'Update' && info != trunk){
confirmGetMessage(iteration);
}
else {
alert('seems to work')
}
}
function baseName(str) {
var base = new String(str).substring(str.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") != -1)
base = base.substring(0, base.lastIndexOf("."));
return base;
}
function trythis(){
alert('made it right here!');
}
function confirmGetMessage(info){
var message = "<h3>" + info + "</h3><br/>Or Revert Back to Trunk?"; var contmessage = "Updating " + info;
swal({
title: "Update Branch?",
html: message,
type: "question",
showCancelButton: true,
cancelButtonText: "Switch To Trunk",
cancelButtonColor: "#0080FF",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Continue Update",
closeOnConfirm: false,
closeOnCancel: false
}).then(
function(result){
swal({
text: contmessage,
timer: 1400,
showConfirmButton: false
}), alert('work please');
}, function(dismiss) {
swal({
text: 'Switching to Trunk',
timer: 1400,
showConfirmButton: false
});
}
);
}
</script>
所以,如果你运行这个代码,弹出警告框从sweetalert的消息框。
---------- UPDATE ---------------
运行代码,像这样似乎越来越近,虽然现在警报消息闭幕消息之前仍然发生,但至少这个时候,我可以看到收消息
function validateSubmit(a,b,c){
var mode = a;
var info = b;
var trunk = c;
var iteration = baseName(info);
if (mode === 'Update' && info != trunk){
confirmGetMessage(iteration);
}
else {
alert('seems to work')
}
}
function baseName(str) {
var base = new String(str).substring(str.lastIndexOf('/') + 1);
if(base.lastIndexOf(".") != -1)
base = base.substring(0, base.lastIndexOf("."));
return base;
}
function trythis(){
alert('made it right here!');
}
function confirmGetMessage(info){
var message = "<h3>" + info + "</h3><br/>Or Revert Back to Trunk?";
var contmessage = "Updating " + info;
swal({
title: "Update Branch?",
html: message,
type: "question",
showCancelButton: true,
cancelButtonText: "Switch To Trunk",
cancelButtonColor: "#0080FF",
confirmButtonColor: "#DD6B55",
confirmButtonText: "Continue Update",
closeOnConfirm: false,
closeOnCancel: false
}).then(function(){
swal({
text: contmessage,
timer: 1400,
showConfirmButton: false
},trythis())
}, function(dismiss){
if (dismiss === 'cancel'){
swal({
text: 'Switching to Trunk',
timer: 1400,
showConfirmButton: false
})
}
}
)}