jQuery Ui对话框按钮,如何添加类? [英] jQuery Ui Dialog Buttons, How to add class?
问题描述
我在另一个线程上找到了这个答案。
使用此语法,如何你添加一个特定按钮的类吗?
$(#mydialog)对话框({
按钮: {
'确认':function(){
// do something
$(this).dialog('close');
},
'取消' :function(){
$(this).dialog('close');
}
}
});
看起来好像没有一个很好的方法通过API执行此操作,但您可以在 创建
:
$(#dialog)。 b $ b按钮:{
'确认':function(){
// do something
$(this).dialog('close');
},
'取消':function(){
$(this).dialog('close');
}
},
create:function(){
$(this).closest(。ui-dialog)
.find(。ui-button:first)//第一个按钮
.addClass(custom);
}
});
如果您想要第二个按钮,可以使用:
$ b $($)$($)$($)code $()这个.closest(ui-dialog)。 //第二个按钮
关键是 $(this).closest (.ui-dialog)。find(。ui-button)
,这将选择对话框中的按钮。之后,您可以应用任何您想要的选择器(包括:contains(...)
,如果您要根据其文本而不是其选择按钮订单)。
以下是一个示例: http:// jsfiddle。 net / jjdtG /
另请注意,您应用的类的CSS选择器必须比jQueryUI的内置类更具体,
I found this answer on another thread..
How to add multiple buttons in Jquery UI dialog box?
Using this syntax, how do you add class to a particular button?
$("#mydialog").dialog({
buttons: {
'Confirm': function() {
//do something
$(this).dialog('close');
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
It doesn't look like there's a great way to do this via the API, however you could add the classes in an event handler for 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");
}
});
If you wanted the second button, you could use:
$(this).closest(".ui-dialog").find(".ui-button").eq(1).addClass("custom") // The second button
The key is the $(this).closest(".ui-dialog").find(".ui-button")
, which will select the buttons in your dialog. After that, you could apply any selector you want (including :contains(...)
which might be useful if you want to select a button based on its text instead of its order).
Here's an example: http://jsfiddle.net/jjdtG/
Also note the CSS selector for the class you're applying has to be more specific than jQueryUI's built-in classes for it to be applied.
这篇关于jQuery Ui对话框按钮,如何添加类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!