用JQuery UI dialog实现Alert和Confirm功能

半城伤御伤魂 提交于 2020-02-27 04:17:17
         JQuery UI dialog虽然可以实现AlertConfirm功能,但每次都要定义相关dialog内容是比较麻烦的。如果只需要简单的调用ShowMsg内容)这样就会省上很多事情,其实只要在JQuery UI dialog的基础上做些简单的工作就可以了。

把功能封装到一个用户控件中,有需要直接引用就可以了。

<%@ Control Language="C#" AutoEventWireup="true" %>

                   <div id="AlertMessage" title="信息确认">

                    <p id="AlertMessageBody"  class="msgbody"></p>

                   </div>

                   <div id="ConfirmMessage" title="信息提问">

                   <p id="ConfirmMessageBody" class="msgbody""></p>

                   </div>

                            <script>

                       $(document).ready(function() {

                           $('#AlertMessage').dialog({

                               autoOpen: false,

                               width: 300,

                               modal: true,

                               buttons: {

                                   "取消": function() {

                                       $(this).dialog("close");

                                   }

                               }

                           });

                           $('#ConfirmMessage').dialog({

                               autoOpen: false,

                               width: 300,

                               modal: true,

                               buttons: {

                                   "取消": function() {

                                       $(this).dialog('close');

                                       mDialogCallback(false);

                                   },

                                   "确定": function() {

                                        $(this).dialog('close');

                                       mDialogCallback(true);

                                   }

                               }

                           });

                       });

                       var mDialogCallback;

                       function ShowMsg(msg, callback) {

                           if (callback == null) {

                               $('#AlertMessageBody').html(msg);

                               $('#AlertMessage').dialog('open');

                           }

                           else {

                               mDialogCallback = callback;

                               $('#ConfirmMessageBody').html(msg);

                               $('#ConfirmMessage').dialog('open');

                           }

                       };

                   </script>

 

这样以后使用起来就省些事了:

ShowMsg('是否提交活动信息?', function(yes) {

                if (yes) {

                   

                }

            });

 

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