如何创建自定义[确认" &放大器;暂停JS执行,直到用户点击按钮?自定义、放大器、按钮、用户

2023-09-10 13:41:26 作者:爱〃到此为止

好吧,我做了一堆RIA / AJAX的东西,需要创建一个pretty的,定制的确认框,这是一个DIV(不是内置的JavaScript确认)。我无法确定如何实现暂停在执行给用户一个机会,接受或要么再开始或停止执行之前下降的情况。 (取决于他们的答案)

Ok, I'm doing a bunch of RIA/AJAX stuff and need to create a "pretty", custom confirm box which is a DIV (not the built-in javascript confirm). I'm having trouble determining how to accomplish a pause in execution to give the user a chance to accept or decline the condition before either resuming or halting execution. (depending upon their answer)

因此​​,这里的逻辑,我处理的一般流程:

So here's the general flow of logic I'm dealing with:

用户从下拉列表中选择一个项目,然后点击按钮。 在客户端JavaScript事件处理程序的按钮,我需要检查(这是关键),对他们在下拉选择项条件系列。 在这些条件可能可能导致不显示在所有任何确认或可能只是一些条件可以评估为真,这意味着我需要让用户接受或继续之前拒绝的条件。只有一个确认应该显示的时间。

要证明的逻辑:

function buttonEventHandler() {

if (condition1) {
  if(!showConfirmForCondition1) // want execution to pause while waiting for user response.
     return; // discontinue execution
}

if (condition2) {
  if (!showConfirmForCondition2) // want execution to pause while waiting for user response.

     return; // discontinue execution
}

if (condition3) {
  if (!showConfirmForCondition3) // want execution to pause while waiting for user response.

     return; // discontinue execution
}

...  
}

如果有人之前已经处理了这一挑战,并找到了解决方案,帮助将是很大的AP preciated。作为一个说明,我还使用了 MS阿贾克斯和的jQuery 的图书馆,虽然我还没有发现,可能已经包含在那些对于这个问题的任何功能。

If anybody has dealt with this challenge before and found a solution, help would be greatly appreciated. As a note, I'm also using the MS Ajax and jQuery libraries although I haven't found any functionality that may already be included in those for this problem.

推荐答案

我不敢说,这是不可能暂停JavaScript运行在相同的方式,确认和警告对话框暂停。要与你将要分手的code成多块,对自定义的确认框事件处理程序调用code下一节一个DIV做到这一点。

I'm afraid to say that it's not possible to pause the Javascript runtime in the same way that the "confirm" and "alert" dialogs pause it. To do it with a DIV you're going to have to break up your code into multiple chunks and have the event handler on the custom confirm box call the next section of code.

已经有一些项目带来延续支持成JavaScript,如叙事的Javascript 所以,如果你'我们真的很热衷于得到它在code单块工作,你可能会考虑这样做。

There have been some projects to bring "continuations" support into Javascript, such as Narrative Javascript so if you're really keen on getting it to work in a single block of code you could look into that.