在对话框标题部分添加按钮?
问题描述:
我想在对话框的头部添加两个按钮以及'x'图标,但我只能在底部添加按钮,即使搜索了几个小时后,我也没有得到任何添加它们的解决方案在顶部或从底部到顶部改变他们的位置。请帮助我。在对话框标题部分添加按钮?
$(function(){
var winsize = ["width=400,height=500"];
var newwin = function() {
window.open("http://www.google.com", "New Window", winsize);
$(this).dialog("close");
}
var hide = function() {}
var btns = {
buttons: {
"+": newwin,
"-": hide
}
};
$("#dialog").dialog(btns);
});
答
这是丑陋的,但也许在正确的方向踢...
//create dialog
$("#dialog2").dialog({
height: 140,
modal: true,
autoOpen: false
});
//add a button
$("<a href='#' style='float:right; margin-right:1em;'></a>").button({icons:{primary: "ui-icon-plus"},text: false}).insertBefore('.ui-dialog-titlebar-close').click(function(e){
e.preventDefault();
alert("click");
});
+0
非常感谢,这正是我一直在寻找的东西,你真的很棒:) –
+0
如果这是你正在寻找的答案,为什么不把它作为答案? – Homer
答
我已经通过在对话框的标题中放置常规按钮来解决这个问题。当然,你必须手动连接它们,所以这不是一个简单的解决方案。
答
你也可以做到以下几点:
var titlebar = dialog.parents('.ui-dialog').find('.ui-dialog-titlebar');
$('<button>-</button>')
.appendTo(titlebar)
.click(function() {
// smth here
});
$('<button>+</button>')
.appendTo(titlebar)
.click(function() {
//smth here
});
或更换使用jQuery图标“ - ”和“+”
<span class="ui-icon ui-icon-minusthick">minimize</span>
你可以显示你到目前为止的代码吗? –
请将此添加到原始问题中,以便阅读和帮助。 –
其中是dialogOpts被设置? – Patricia