jQuery UI Alert Dialog as a replacement for alert()

前端 未结 9 570
独厮守ぢ
独厮守ぢ 2020-12-13 18:51

I\'m using alert() to output my validation errors back to the user as my design does not make provision for anything else, but I would rather use jQuery UI dial

9条回答
  •  轮回少年
    2020-12-13 19:43

    I took @EkoJR's answer, and added an additional parameter to pass in with a callback function to occur when the user closes the dialog.

    function jqAlert(outputMsg, titleMsg, onCloseCallback) {
        if (!titleMsg)
            titleMsg = 'Alert';
    
        if (!outputMsg)
            outputMsg = 'No Message to Display.';
    
        $("
    ").html(outputMsg).dialog({ title: titleMsg, resizable: false, modal: true, buttons: { "OK": function () { $(this).dialog("close"); } }, close: onCloseCallback }); }

    You can then call it and pass it a function, that will occur when the user closes the dialog, as so:

    jqAlert('Your payment maintenance has been saved.', 
            'Processing Complete', 
            function(){ window.location = 'search.aspx' })
    

提交回复
热议问题