如何更改窗体顶部的jquery UI对话框按钮位置?

时间:2013-06-10 23:48:18

标签: jquery jquery-ui

如何将按钮位置更改为页面顶部?我已经尝试了很多例子,但是那些只显示在左边。但是我想在表格顶部显示按钮。

      $( "#popup" ).click(function() {
$( "#dialog-form" ).dialog( "open" );
});

$( "#dialog-form" ).dialog({ 
 autoOpen: false,
 height: 300,
 width: 350,
 modal: true,
 buttons : {
 "search" : function(){
 $(this).css({position:top})
 },
 "use selected" : function(){}
 }

 });

3 个答案:

答案 0 :(得分:2)

请在打开对话框时尝试添加按钮元素位置,就像下面的代码段

一样
$('#dialog-form').dialog({
  open: function (event, ui) {
    $(this).prepend($(this).parent().find('.ui-dialog-buttonpane'));
  },
  ...

答案 1 :(得分:1)

我喜欢Cliff的答案,但我会使用.before()代替.prepend(),因为这会使你的按钮窗格和内容元素保持在同一级别。

$('#dialog-form').dialog({
    open: function (event, ui) {
        $(this).before($(this).parent().find('.ui-dialog-buttonpane'));
    },
    ...

然后我还会更改按钮窗格的边框。 (取决于你的主题)

Css

.ui-dialog .ui-dialog-buttonpane {
    border-top-width:0px; border-bottom-width:1px;
}

答案 2 :(得分:0)

查看此fiddle

基本上,你的CSS:

div.ui-dialog-buttonpane {
    position: absolute;
    /* height + padding + margin of header */
    top: 41px;
    /* play around with this setting to your liking. */
    width: 97%;
    /* use a more specific selector to avoid using !important */
    padding: 0 !important;
}
/* for a bottom border use this */
div.ui-dialog-buttonpane {
    /* use a more specific selector to avoid using !important */
    border-width: 0 0 1px 0 !important;
}