2015-10-17 123 views
0

我正在尝试使用JQuery dialog,实际上我在这方面没有任何问题。现在我想用我的alert confirmation替换为JQuery Dialog Confirmation,问题是当我显示JQuery Dialog时代码继续工作,并且不会等待JQuery Dialog响应。我想这样做是创建一个模式,以等待JQuery dialog结果,并继续执行代码。按下按钮如何等待JsDialog响应?

function start(title, message, messageButtons) 
{ 
    //messageButtons => contains the buttons with the function see bottom 

    if(confirm) 
    { 
     jQuery("body").append(
     "<div id='message_box' title='" + title + "'>" + 
     "<p>" + message + "</p>" + 
     "</div>" 
     );  

     jQuery("#message_box").dialog({ 
      autoOpen: false, 
      modal: true, 
      resize: "auto", 
      width: 400, 
      height: "auto", 
      resizable: false, 
      buttons: messageButtons, 
      closeOnEscape: true 
      }); 
    } 
    else 
    { 
     console.log("No response"); 
    } 
} 

留言按钮结构之后

功能触发:

var messageButtons = {}; 
    messageButtons['OK'] = function() 
    { 
     confirm = true; 
    }; 

    messageButtons[EALang['cancel']] = function() 
    { 
     confirm = false; 
     $('#message_box').dialog('close'); 
    }; 

JQuery Dialog显示正常,但在浏览器控制台我的用户之前获得No response选择一个答案从JQuery Dialog。所以主要的问题是在出现JQuery Dialog后停止js代码,等待用户选择,然后继续上面的代码。你如何看到我在按钮函数中设置了confirm变量,当用户按下相应的按钮并且这个工作正常时调用这个函数。

回答

0

你应该尝试使用一个回调来执行任何你想要的代码在js.Dialog某一点,这似乎是一个回调相当不错,这里是关于一些信息:http://code.kolmio.com/jsdialog/Docs/Callbacks.html

此外,以后要保存一段代码的方法是设置超时时间:http://www.w3schools.com/jsref/met_win_settimeout.asp

+0

还有另一种方法可以做到这一点吗? – Dillinger

+0

请问一个更具体的问题。 –

+0

什么不清楚? – Dillinger