Confirm box return value from alertify plugin and jquery

与世无争的帅哥 提交于 2019-12-12 20:24:45

问题


I have a confirm dialog for my form. it is inside a jquery submit function. I am using alertify to show the confirm dialog. But problem is my jquery submit function returns before alertify gets the confirm box value. Read that alertify is non blocking. Any way to overcome this and return the confirm box value back to my form?

$("#viewform").submit(function(){

      alertify.confirm("Delete the selected entry?",function(e){

             if(e)
                    return true;
              else 
                     return false;

               });


 });

The function always returns true. I want to return the output of confirm box. How can i return the delayed return value of confirm box?


回答1:


One work around would be to used a button rather than a submit input, then use a click listener to run alertify. This could then submit your form via jQuery. Here's how it might look:

HTML:

<form id="form">
    <input type="button" value="Submit" id="btn">
</form>

JavaScript:

$('#btn').click(function() {
    alertify.confirm("Delete the selected entry?",function(e){
        if(e) {
            $('#form').submit();
            return true;
        } else {
            return false;
        }

    });
});


来源:https://stackoverflow.com/questions/15876289/confirm-box-return-value-from-alertify-plugin-and-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!