2011-06-24 26 views
3

我想在對話框的頭部添加兩個按鈕以及'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); 
}); 
+0

你可以顯示你到目前爲止的代碼嗎? –

+0

請將此添加到原始問題中,以便閱讀和幫助。 –

+0

其中是dialogOpts被設置? – Patricia

回答

3

這是醜陋的,但也許在正確的方向踢...

http://jsfiddle.net/AjKFe/48/

//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

0

我已經通過在對話框的標題中放置常規按鈕來解決這個問題。當然,你必須手動連接它們,所以這不是一個簡單的解決方案。

0

你也可以做到以下幾點:

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>