Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.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_Css_Class - Fatal编程技术网

将类添加到jquery对话框按钮

将类添加到jquery对话框按钮,jquery,css,class,Jquery,Css,Class,我想在jquery对话框的按钮上添加css类 这是我的密码: $(document).ready(function(){ $('#messageBox p').html('bla bla bla. Ok?'); $('#messageBox').dialog({ modal : true, buttons: { 'Yes': function() { doSomething();

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

这是我的密码:

$(document).ready(function(){
      $('#messageBox p').html('bla bla bla. Ok?'); 
      $('#messageBox').dialog({
        modal : true,
        buttons: {
          'Yes': function() {
            doSomething();
            $(this).dialog('close');
          }, 
          'No': function() {
            doAnotherThing();
            $(this).dialog('close');
          }
        }
      });
    });
例如,我想在“是”按钮上添加“.red”类

我该怎么做

谢谢大家!

您尝试过该函数吗?

.addClass函数

对话框函数中有一个对话框类选项,可用于为对话框本身指定css类。您可以给它一个唯一的类名,并使用该类名获取对对话框的任何子元素的引用。然后,使用选择器按位置或其包含的文本获取对子按钮的引用(使用前者可能更有效)。

多亏了Rich:

$(document).ready(function(){
      $('#messageBox p').html('bla bla bla. Ok?'); 
      $('#messageBox').dialog({
        modal : true,
        dialogClass: 'dialogButtons',
        buttons: {
          'Yes': function() {
                doSomething();
                $(this).dialog('close');
          }, 
          'No': function() {
                doAnotherThing();
                $(this).dialog('close');
          }
        }
      });
    });
$("div.dialogButtons div button:nth-child(1)").addClass("oneCssClass");
$("div.dialogButtons div button:nth-child(2)").addClass("anotherCssClass");

解决了

也有同样的问题。与nico的解决方案非常相似,但将样式添加到对话框的open函数中:

open: function () {
                // add style to buttons (can't seem to do this via the button definition without breaking IE)
                $(".someDialog .ui-dialog-buttonset button:first").not(".buttonPrimary").addClass("buttonPrimary");
                $(".someDialog .ui-dialog-buttonset button:last").not(".buttonSecondary").addClass("buttonSecondary");
                $("#someDialog").focus();
            }

我也遇到过类似的情况,在显示对话框之前,我需要在按钮上添加一些样式。去按按钮不是很简单,所以我想出了一个非常简单的方法去按按钮。在创建对话框按钮的过程中,我只给了它们一个“id”,然后我就可以使用常用的jquery选择器获取对它们的引用<代码>$(“#btnDelete”).addClass(“已禁用”)


但是在哪里添加addclass函数呢?和phoenix一样的答案。。。我可以把addClass函数放在哪里,因为按钮是由jquery对话框制作的,并且按钮没有ID。是的,我知道这个函数。。。但我不知道如何在我的情况下使用它。这是最好的答案!注意:在class属性周围使用引号,在iPad上它会抛出一个错误(可能是因为class是一个保留(关键字)字),在IE8中也是同样的错误。用
“class”
而不是
class
拯救了我的一天谢谢
buttons: [
            {
               text: "Submit",
               "class": 'submit_class_name',
               click: function() {                     
                  $(this).dialog("close"); 
               }
            },
            {
               text: "Cancel",
               click: function() { 
                  $(this).dialog("close"); 
               }
            }
          ]
buttons: [{
        id: "btnDelete",
        text: "Delete",
        click: function () {
            Delete();
            $(this).dialog('close');
        }
    }, {
        id: "btnSave",
        text: "Save",
        click: function () {
            Save();
            $(this).dialog('close');
        }
    }, {
        id: "btnCancel",
        text: "Cancel",
        click: function () {
            $(this).dialog("close");
        }
    }]