简体   繁体   中英

How to pass the button name as variable in jquery dialogue box

I want to call the default action of dialogue box button, so please tell me how to pass the variable in side the dialogue box initialization. Here is my try for that :

Calling the dialogue box with default function of 'Yes' button

$( "#confirmComplete" ).dialog( "option", "buttons:Yes");

$( "#confirmComplete" ).dialog({
     autoOpen: false,
     resizable: false,
     modal: true,
     async:false,
     position: 'top',
     buttons: {
         "Yes": function() {
                //SOME FUNCTIOANLITY
         }
     }
 })

Put the code in a named function, call the function:

function doYes() {
    // some functionality
}

$("#confirmComplete").dialog({
    autoOpen: false,
    resizable: false,
    modal: true,
    async: false,
    position: "top",
    buttons: {
        "Yes": doYes
    },
});

doYes(); // Call the default button action

You could do:

buttons: {
  "Yes": function() {
    $(this).dialog("close");
    return true;
  }
}

You could also have a No button that closes dialog and return false;

Based on the true / false returned, you can take further actions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM