简体   繁体   English

如何在jQuery对话框中将按钮名称作为变量传递

[英]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; 您还可以使用“ No按钮关闭对话框并return false;

Based on the true / false returned, you can take further actions. 根据返回的true / false ,您可以采取进一步的措施。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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