Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在我的jquery对话框的按钮上添加类_Jquery_Jquery Ui Dialog - Fatal编程技术网

在我的jquery对话框的按钮上添加类

在我的jquery对话框的按钮上添加类,jquery,jquery-ui-dialog,Jquery,Jquery Ui Dialog,我有一个jQuery对话框: // Configure buttons var dialogButtons = {}; dialogButtons[buttonConfirm] = function () { $.ajax({ type: "Post", url: href, cache: false, success: function (data) { v

我有一个jQuery对话框:

    // Configure buttons
    var dialogButtons = {};

    dialogButtons[buttonConfirm] = function () {
        $.ajax({
            type: "Post",
            url: href,
            cache: false,
            success: function (data) { var func = success; window[func](data); }
        });
        $(this).dialog("close");
    };

    dialogButtons[buttonCancel] = function () {
        $(this).dialog("close");
    };

    // Configure dialog
    $dialog.dialog(
        {
            modal: true,
            closeOnEscape: true,
            resizable: false,
            buttons: dialogButtons
        });

    // Opening dialog
    $dialog.dialog('open');
我的问题:我想在我的按钮上设置一个特定的类“btn”。我该怎么做


谢谢

@科林有一个答案,但我想我应该更具体地回答这个对话。jqueryui有一个
小部件
方法,它返回由对话框本身组成的元素。结合定位
ui按钮
class,您可以得到您想要的:

$dialog.dialog('widget') // Grab widget (UI element)
  .find('.ui-button')    // Locate buttons within
  .addClass('btn');      // hadd btn class to them

编辑:还有一个例子:

如果您查看源代码,在
jquery.ui.dialog.js
的方法
\u createButtons
中,您将看到由按钮文本索引的哈希如果不是函数,则被视为属性集合。因此,您可以执行以下操作:

var $dlg = $('#dlg').dialog({
    buttons: {
        'firstButton': {            
            'click': function() {
                $dlg.dialog('close');
            },
            'text' : 'OK',         
            'class': 'myclass'
        },
        'Cancel': function(){
            $dlg.dialog('close');
        }
    }
});

下面是Brad的一把小提琴,演示了代码

为什么要在类中添加按钮?使用他们的类(
ui按钮)
)你应该避免重复使用轮子…我有一个特定的CSS文件,它为我的所有表格、按钮提供了标准的外观。。。添加类btn或主或。。。在我的按钮(任何地方)上,我都可以改变原色和其他一些很酷的东西的颜色。
var $dlg = $('#dlg').dialog({
    buttons: {
        'firstButton': {            
            'click': function() {
                $dlg.dialog('close');
            },
            'text' : 'OK',         
            'class': 'myclass'
        },
        'Cancel': function(){
            $dlg.dialog('close');
        }
    }
});