This article describes in detail the simple implementation and encapsulation of the dialog box using jquery. The specific implementation code is as follows. If you are interested, refer to the following code and hope to help you.
The Code is as follows:
Var _ alert_iconCss = "tipmsg_icoInfo ";
Var _ confirm_iconCss = "tipmsg_icoConfirm ";
Var _ error_iconCss = "tipmsg_icoError ";
Var _ warning_iconCss = "tipmsg_icoWarning ";
Function dialogInit (type, msg ){
Var iconCss = "";
Switch (type ){
Case "confirm": iconCss = _ confirm_iconCss; break;
Case "error": iconCss = _ error_iconCss; break;
Case "warning": iconCss = _ warning_iconCss; break;
Default: iconCss = _ alert_iconCss; break;
}
Var htmlStr ="
"+ Msg +"
";
Return htmlStr;
}
Function Alert (msg, okCallback ){
Var title = "prompt ";
Var type = "alert ";
Var html = dialogInit (type, msg );
Var p = $ ("body"). find ("#" + type + "Div ");
P. remove ();
$ ('Body'). append ($ (html ));
Var buttons = {"OK": function (){
If (okCallback) okCallback ();
$ (This). dialog ("close ");
}
};
$ ("#" + Type + "Div"). dialog ({
Modal: true,
Title: title,
Buttons: buttons
});
}
Function Confirm (msg, okCallback, cancelCallback ){
Var title = "OK ";
Var type = "confirm ";
Var html = dialogInit (type, msg );
Var p = $ ("body"). find ("#" + type + "Div ");
P. remove ();
$ ('Body'). append ($ (html ));
Var buttons = {"OK": function (){
If (okCallback) okCallback ();
$ (This). dialog ("close ");
},
"Cancel": function (){
If (cancelCallback) cancelCallback ();
$ (This). dialog ("close ");
}
};
$ ("#" + Type + "Div"). dialog ({
Modal: true,
Title: title,
Buttons: buttons
});
}
Function Error (msg, okCallback ){
Var title = "error ";
Var type = "error ";
Var html = dialogInit (type, msg );
Var p = $ ("body"). find ("#" + type + "Div ");
P. remove ();
$ ('Body'). append ($ (html ));
Var buttons = {"OK": function (){
If (okCallback) okCallback ();
$ (This). dialog ("close ");
}
};
$ ("#" + Type + "Div"). dialog ({
Modal: true,
Title: title,
Buttons: buttons
});
}
Function Warning (msg, okCallback ){
Var title = "warning ";
Var type = "warning ";
Var html = dialogInit (type, msg );
Var p = $ ("body"). find ("#" + type + "Div ");
P. remove ();
$ ('Body'). append ($ (html ));
Var buttons = {"OK": function (){
If (okCallback) okCallback ();
$ (This). dialog ("close ");
}
};
$ ("#" + Type + "Div"). dialog ({
Modal: true,
Title: title,
Buttons: buttons
});
}