Javascript 同步jquery警报

Javascript 同步jquery警报,javascript,jquery,Javascript,Jquery,我有下面的功能 function test() { jAlert("One","DescriptionOne"); // First jAlert jAlert("Two","DescriptionOne"); // Second jAlert window.location = 'test.html' } 运行此代码时,第一个jAlert出现并消失,而不单击OK按钮。现在第二个jAlert也会发生同样的情况 不单击任何“确定”按钮。我知道我必须提供回拨功能,但我的要

我有下面的功能

function test()
{
  jAlert("One","DescriptionOne"); // First jAlert
  jAlert("Two","DescriptionOne"); //    Second jAlert
  window.location = 'test.html'
}    
运行此代码时,第一个jAlert出现并消失,而不单击OK按钮。现在第二个jAlert也会发生同样的情况 不单击任何“确定”按钮。我知道我必须提供回拨功能,但我的要求是不使用任何回拨功能

请帮助我如何

  • 让第二个jAlert等待,直到用户单击第一个jAlert的OK按钮
  • 单击第二个jAlert的Ok按钮后加载test.html
  • 像这样的

    function test()
    {
      jAlert("One","DescriptionOne", function() {
        jAlert("Two","DescriptionOne", function() {
          window.location = 'test.html';
        }) //    Second jAlert
      }); // First jAlert
    }    
    

    可能重复使用不带回调的异步函数?祝你好运参见@Toverbal的答案:)好吧,使用回调就可以了。但是我希望下一行的执行被阻止,直到用户点击OK。这在没有回调函数的情况下是可能的吗?不,你必须通过回调来实现。由于事件驱动的体系结构,您无法执行此操作,如果您在代码中添加诸如while(!buttonPressed)之类的内容,整个浏览器将锁定。