Javascript 如何在 Jquery UI 对话框中添加多个按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2512463/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 00:41:34  来源:igfitidea点击:

How to add multiple buttons in Jquery UI dialog box?

javascriptjquerydialog

提问by Vonder

I would like to have more than one button. I tried to copy code between brackets but doesnt work.Ideas?

我想要不止一个按钮。我试图在括号之间复制代码但不起作用。想法?

buttons: {

"Close": function() {
 $(this).dialog("close");

}

回答by Nick Craver

Create them using this format, 'button text': function() { }with a comma inbetween, like this:

使用这种格式创建它们,'button text': function() { }中间有一个逗号,如下所示:

$("#mydialog").dialog({
  buttons: {
    'Confirm': function() {
       //do something
       $(this).dialog('close');
    },
    'Cancel': function() {
       $(this).dialog('close');
    }
  }
});

回答by jgibbs

To add to this, the button array method is useful to know about as it exposes more functionality per button, such as adding icons and other per-button properties. The points to note being the added square brackets around the set of buttons turning it into an array of buttons, and the extra curly braces around each button object.

除此之外,按钮数组方法很有用,因为它为每个按钮公开了更多功能,例如添加图标和其他每个按钮的属性。需要注意的一点是在按钮组周围添加方括号,将其转换为按钮数组,以及每个按钮对象周围的额外花括号。

$("#mydialog").dialog({
  buttons: [{
    text: 'Confirm',
    icons: {
        primary: "ui-icon-check"
    },
    click: function() {
       //do something
       $(this).dialog('close');
    }},{
    text: 'Cancel',
    icons: {
        primary: "ui-icon-cancel"
    },
    click: function() {
       $(this).dialog('close');
    }
  }]
});