【问题标题】:jQuery UI dialog button positioned on the left位于左侧的 jQuery UI 对话框按钮
【发布时间】:2020-12-01 12:56:27
【问题描述】:

我有一个对话框定义如下:

 $('#dgReport').dialog({
            modal: true,
            autoOpen: false,
            width: 450,
            title: '',
            resizable: false,
            buttons: [
                {
                    text: 'Prev',
                    id: 'btnPrevReport',
                    click: function () { }
                },

                {
                    text: 'Next',
                    id: 'btnNextReport',
                    click: function () { }
                },


                {
                    text: 'Save',
                    click: function () {
                        
                    }
                },
                {
                    text: 'Cancel',
                    click: function () {
                        $(this).dialog('close');
                    }
                }
            ],
            open: function () {}
};

我希望 Prev 和 Next 按钮位于左侧,Save 和 Cancel 位于右侧,是否可以不使用 window-pane 类?

【问题讨论】:

    标签: jquery jquery-ui jquery-ui-dialog


    【解决方案1】:

    你可以在the create event内部行动:

    create: function (e) {
        var dbs = $(this).closest('.ui-dialog').find('.ui-dialog-buttonset');
        dbs.css('width', '100%');
        dbs.find('.ui-button:contains("Save"), .ui-button:contains("Cancel")')
                                       .css({'float': 'right', 'margin-right': '0px'});
    }
    

    $('button').on('click', function(e) {
        $('#dgReport').dialog( "open" );
    });
    $('#dgReport').dialog({
        modal: true,
        autoOpen: false,
        width: 450,
        title: '',
        resizable: false,
        buttons: [
            {
                text: 'Prev',
                id: 'btnPrevReport',
                click: function () { }
            },
    
            {
                text: 'Next',
                id: 'btnNextReport',
                click: function () { }
            },
    
    
            {
                text: 'Save',
                click: function () {
    
                }
            },
            {
                text: 'Cancel',
                click: function (e) {
                    $(this).dialog('close');
                }
            }
        ],
        create: function (e) {
            var dbs = $(this).closest('.ui-dialog').find('.ui-dialog-buttonset');
            dbs.css('width', '100%');
            dbs.find('.ui-button:contains("Save"), .ui-button:contains("Cancel")').css({'float': 'right', 'margin-right': '0px'});
        }
    });
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
    
    
    <button>Open Dialog</button>
    <div id="dgReport" title="Basic dialog">
        <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
    </div>

    【讨论】:

    • 非常感谢!
    猜你喜欢
    • 2010-10-31
    • 2018-08-01
    • 2013-06-14
    • 2010-12-20
    • 2011-02-01
    • 2011-01-28
    • 1970-01-01
    • 2015-05-23
    • 1970-01-01
    相关资源
    最近更新 更多