jQuery UI Alert Dialog as a replacement for alert()

前端 未结 9 604
独厮守ぢ
独厮守ぢ 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:44

    Building on eidylon's answer, here's a version that will not show the title bar if TitleMsg is empty:

    function jqAlert(outputMsg, titleMsg, onCloseCallback) {
        if (!outputMsg) return;
    
        var div=$('
    '); div.html(outputMsg).dialog({ title: titleMsg, resizable: false, modal: true, buttons: { "OK": function () { $(this).dialog("close"); } }, close: onCloseCallback }); if (!titleMsg) div.siblings('.ui-dialog-titlebar').hide(); }

    see jsfiddle

提交回复
热议问题