我发现这个答案在另一个线程..
How to add multiple buttons in Jquery UI dialog box?
使用这个语法,你如何添加类到特定的按钮?
$("#mydialog").dialog({
buttons: {
'Confirm': function() {
//do something
$(this).dialog('close');
},'Cancel': function() {
$(this).dialog('close');
}
}
});
解决方法
它看起来不像有一个伟大的方法来通过API做这个,但你可以添加类在事件处理程序为
create:
$("#dialog").dialog({
buttons: {
'Confirm': function() {
//do something
$(this).dialog('close');
},'Cancel': function() {
$(this).dialog('close');
}
},create:function () {
$(this).closest(".ui-dialog")
.find(".ui-button:first") // the first button
.addClass("custom");
}
});
如果你想要第二个按钮,你可以使用:
$(this).closest(".ui-dialog").find(".ui-button").eq(1).addClass("custom") // The second button
关键是$(this).closest(“。ui-dialog”)。find(“。ui-button”),它将选择对话框中的按钮。之后,你可以应用你想要的任何选择器(包括:contains(…),如果你想基于它的文本而不是它的顺序选择按钮,这可能是有用的)。
这里有一个例子:http://jsfiddle.net/jjdtG/
还要注意,您所应用的类的CSS选择器必须比jQueryUI的内置类更具体,以便应用。