将自定义方法添加到jQuery UI对话框 [英] add custom method to jquery ui dialog
本文介绍了将自定义方法添加到jQuery UI对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我该如何做:
$("#some_div").dialog("doSomething");
该方法应该做的是在标题栏中添加一个额外的图标
And what that method should do is to add an extra icon in the titlebar
编辑1 :我已经尝试过此解决方案:该方法被调用,但我无法访问对话框对象(也许我做错了什么)
EDIT 1: I've tried this solution: the method gets called but I can't access the dialog object (maybe I'm doing something wrong)
推荐答案
好的,这就是我所做的:
Ok, this is what I did:
//in a separate js file
$.ui.dialog.prototype.showExtraButton = function()
{
this.uiDialogTitlebar.append("<a role='button' class='ui-dialog-titlebar-icon ui-dialog-titlebar-icon-extra'><span class='ui-icon'></span></a>");
}
//call it this way
$("#some_div").dialog("showExtraButton");
//css
.ui-dialog-titlebar-icon {
position: absolute;
right: 25px;
}
.ui-dialog-titlebar-icon-extra span
{
display: block;
background-image: url(../path_to_img/button_extra.png)!important;
}
兰登(Langdon)的解决方案,以及
This solution by Langdon, along with this one by Kevin B gave me the answer on how to resolve my problem
更新2014年1月3日
TIL,所以这是同一件事的另一种实现方式
TIL about $.widget(), so here is another implementation of the same thing
$.widget("ui.dialog", $.ui.dialog,
{
showExtraButton: function()
{
this.uiDialogTitlebar.append("<a role='button' class='ui-dialog-titlebar-icon ui-dialog-titlebar-icon-extra'><span class='ui-icon'></span></a>");
}
});
这篇关于将自定义方法添加到jQuery UI对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文