Javascript Jquery对话框异步模式
我正在使用jQueryUI对话框编程一个应用程序。在函数onSubmit中,我希望用户可以确认加载文件,但是由于对话框异步模式,代码没有提供确认用户选择的选项。当用户想要选择任何选项时,功能已经结束 有解决这个问题的办法吗 这是代码:Javascript Jquery对话框异步模式,javascript,jquery,jquery-ui,asynchronous,dialog,Javascript,Jquery,Jquery Ui,Asynchronous,Dialog,我正在使用jQueryUI对话框编程一个应用程序。在函数onSubmit中,我希望用户可以确认加载文件,但是由于对话框异步模式,代码没有提供确认用户选择的选项。当用户想要选择任何选项时,功能已经结束 有解决这个问题的办法吗 这是代码: onSubmit:function(files) { var bucle=true; var perm=null; if(res=="0"){ perm=
onSubmit:function(files)
{
var bucle=true;
var perm=null;
if(res=="0"){
perm=true;
}else if(res=="1"){
if(showDialog()){
perm=true;
}else{
perm=false;
}
}
else{
perm=false;
}
res=null;
return perm;
},
以及showDialog功能:
function showDialog(){
$(function() {
$.ui.dialog.prototype._focusTabbable = function(){};
$( "#dialog-confirm" ).dialog({
resizable: false,
height:200,
width:600,
modal: true,
closeText:null,
buttons: {
Ok: function() {
$(this).dialog('close');
return true;
},
Cancel: function() {
$(this).dialog('close');
return false;
}
}
});
});
}
提前谢谢你 由于异步模式,您需要等待用户做出选择。
您可以将下一步作为回调传递给
showDialog
方法
onSubmit:function(files){
//non-relevant code omitted...
showDialog(nextStep)
//non-relevant code omitted...
}
function nextStep(trueOrFalse){
if(trueOrFalse){
// upload your file or do anything you want
}else{
// do another thing
}
}
function showDialog(callback){
//non-relevant code omitted...
buttons: {
Ok: function() {
$(this).dialog('close');
callback(true);
},
Cancel: function() {
$(this).dialog('close');
callback(false);
}
}
//non-relevant code omitted...
}
由于采用异步模式,您需要等待用户做出选择。
您可以将下一步作为回调传递给
showDialog
方法
onSubmit:function(files){
//non-relevant code omitted...
showDialog(nextStep)
//non-relevant code omitted...
}
function nextStep(trueOrFalse){
if(trueOrFalse){
// upload your file or do anything you want
}else{
// do another thing
}
}
function showDialog(callback){
//non-relevant code omitted...
buttons: {
Ok: function() {
$(this).dialog('close');
callback(true);
},
Cancel: function() {
$(this).dialog('close');
callback(false);
}
}
//non-relevant code omitted...
}