asp.net alert美化dialog實現Alert和Confirm功能(轉載)

摘要:asp.net alert美化dialog實現Alert和Confirm功能(轉載)

來源:http://www.cnblogs.com/henryfan/archive/2009/10/14/1583089.html

 

用JQuery UI dialog實現Alert和Confirm功能

         JQuery UI dialog 雖然可以實現Alert 和Confirm 功能,但每次都要定義相關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) {

                   

                }

            });

網頁設計 -->找網站銀行

好站推薦:網頁設計除臭襪