开发者

JQuery popup and how to stop javascript code logic behind

开发者 https://www.devze.com 2023-01-21 20:17 出处:网络
I am using jquery.alert.js library to display alert, it worked great exception one case. In normal situation, if i use the default alert box of Javascript, the box display and user has to click ok but

I am using jquery.alert.js library to display alert, it worked great exception one case. 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. 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

  1. Default alert box

    开发者_如何学编程alert("There is an error");

    Do some thing after user click on OK ..... Some code behind

  2. jAlert box

    
    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?

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. In real, i got the below code logic to validate the inputed data on keypress event.


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.

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()); 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. So i wonder if existing a solution for this?

0

精彩评论

暂无评论...
验证码 换一张
取 消