0

我希望向一个元素添加一个类定义,该元素由button : { }我如何做到这一点而不做类似 $('.ui-dialog-buttonpane button:eq(0)')

http://jsfiddle.net/3zcEY/

     $(function() {
            $( "#dialog-confirm" ).dialog({
              resizable: false,
              height:140,
              modal: true,
              buttons: {
 //add a class definition to the delete all items button here. tried  
//class:'save' didn't work

                "Delete all items": function() {
                  $( this ).dialog( "close" );
                },
                Cancel: function() {
                  $( this ).dialog( "close" );
                }
              }
            });
          });
4

1 回答 1

3

您可以使用选项对象来指定类名。

$("#dialog-confirm").dialog({
        resizable: false,
        height: 140,
        modal: true,
        buttons: {
            //add a class definition here.
            "Delete all items": {
                'class': 'customClass', //<-- specify the class here
                text: 'Delete all items', //<-- text for the button
                click: function () { //click handler
                    $(this).dialog("close");
                }
            },
            Cancel: function () {
                $(this).dialog("close");
            }
        }
    });

小提琴

于 2013-10-21T21:35:11.950 回答