简体   繁体   English

JQuery弹出窗口以及如何阻止javascript代码逻辑落后

[英]JQuery popup and how to stop javascript code logic behind

I am using jquery.alert.js library to display alert, it worked great exception one case. 我正在使用jquery.alert.js库来显示警报,它在一个案例中工作得非常好。 In normal situation, if i use the default alert box of Javascript, the box display and user has to click ok button then the next code logic will be executed. 在正常情况下,如果我使用Javascript的默认警报框,则框显示和用户必须单击确定按钮,然后将执行下一个代码逻辑。 However, in case of jAlert, it is using callback function so it will continue to execute the behind code and don't have to wait for user to click on OK button 但是,对于jAlert,它使用回调函数,因此它将继续执行后面的代码,而不必等待用户单击“确定”按钮

  1. Default alert box 默认警报框

     alert("There is an error"); 

    \n\n

    Do some thing after user click on OK ..... Some code behind 用户点击OK后做一些事情.....一些代码背后

  2. jAlert box jAlert盒子

     jAlert("There is an error", "error", function() { Do some thing afteruser click on OK }); ..... Some code behind 

I wonder if someone could give me some hints for this situation. 我想知道是否有人可以给我一些这方面的提示。 Is there anyway to stop the javascript code executing the code behind until user choose OK button on the box? 无论如何,有没有停止javascript代码执行后面的代码,直到用户在框中选择“确定”按钮?

Thank you in advance. 先感谢您。

jAlert("There is an error", "error", function() {
   Do some thing afteruser click on OK
   .....
   Some code behind
});

Thank you Jakub for your answer and i am sorry i did not clarify my situation well enough. 感谢Jakub的回答,对不起,我没有充分说明我的情况。 In real, i got the below code logic to validate the inputed data on keypress event. 实际上,我得到了以下代码逻辑来验证keypress事件中的输入数据。


if(config.maxlength compare to $(this).val().length){
    jAlert("There is an error");
    $(this).focus();
    event.stopPropagation();
    return;
}
$hidden.attr('value', $(this).val());

As the above content, the jAlert did not wait for user to click on OK button and just call [$(this).focus();], so the cursor is in the parent control and user can not click on OK button on the box. 由于上面的内容,jAlert并不等待用户单击OK按钮,而只是调用[$(this).focus();],因此光标位于父控件中,用户不能单击框。

If i use the default alert box in this case, it will wait user click on OK button then focus back to the validating control 如果我在这种情况下使用默认警报框,它将等待用户单击确定按钮然后重新回到验证控件

As i am customizing an old system, so behind $hidden.attr('value', $(this).val()); 因为我正在定制一个旧系统,所以在$ hidden.attr('value',$(this).val())之后; i got a lot of other logic and sub-logic. 我有很多其他逻辑和子逻辑。 If i have to use if condition like that, i think i could not control all the source code. 如果我必须使用if那样的条件,我想我无法控制所有的源代码。 So i wonder if existing a solution for this? 所以我想知道是否存在解决方案?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM