The detailed code has been uploaded to the resource.
Http://download.csdn.net/source/752922
- // Encapsulate a function to add different events to multiple buttons.
- Function confirmfun (txt, urlstr ){
- Confirm (txt, function (){
- Window. Location. href = urlstr;
- });
- }
- $ (Document). Ready (function (){
- // Original code.
- // $ ('# Confirmdialog input: eq (1)'). Click (function (e ){
- // E. preventdefault ();
- /// Example of calling the confirm Function
- /// You must use a callback function to perform the "yes" Action
- // Confirm ("second button, OK? ", Function (){
- // Window. Location. href = 'HTTP: // www.greatverve.cn /';
- //});
- //});
- // Extended code
- $ ('# Confirmdialog input: eq (1)'). Click (function (e ){
- E. preventdefault ();
- Confirmfun ('second button, OK? ', 'HTTP: // www.greatverve.cn /');
- });
- Alert ('Multiple functions can be executed in ready ');
- });
- $ (Document). Ready (function (){
- $ ('# Confirmdialog input: eq (0)'). Click (function (e ){
- E. preventdefault ();
- Confirmfun ('the first button, OK? ', 'HTTP: // www.greatverve.cn /');
- });
- Alert ('ready can be called multiple times. ');
- });
- Function confirm (message, callback ){
- $ ('# Confirm'). Modal ({
- Close: false,
- Overlayid: 'confirmmodaloverlay ',
- Containerid: 'confirmmodaliner iner ',
- Onshow: function (DIALOG ){
- Dialog. Data. Find ('. message'). append (Message );
- // If the user clicks "yes"
- Dialog. Data. Find ('. Yes'). Click (function (){
- // Call the callback
- If ($. isfunction (callback )){
- Callback. Apply ();
- }
- // Close the Dialog
- $. Modal. Close ();
- });
- }
- });
- }