Add button to jquery ui dialog

后端 未结 4 1401
北恋
北恋 2020-12-14 19:42

I can not add button to this jquery ui dialog. if possible please give me an example . thanks.



        
相关标签:
4条回答
  • 2020-12-14 20:02

    Sometimes you want to add the buttons dynamically after the dialog is created too. See my answer at the question Add a button to a dialog box dynamically

    var mydialog = ... result of jqueryui .dialog()
    var buttons = mydialog.dialog("option", "buttons"); // getter
    $.extend(buttons, { foo: function () { alert('foo'); } });
    mydialog.dialog("option", "buttons", buttons); // setter
    
    0 讨论(0)
  • 2020-12-14 20:04

    If you want to add a button to a dialog that is already open you can do something like:

    var buttonSet = $('#dialog').parent().find('.ui-dialog-buttonset');
    var newButton = $('<button>My New Button</button>');
    newButton.button().click(function () {
        alert('My new button clicked');
    });
    buttonSet.append(newButton);
    
    0 讨论(0)
  • 2020-12-14 20:15

    Here is an example

    add this to your function:

    buttons: {
                    OK: function() { //submit
                        $( this ).dialog( "close" );
                    },
                    Cancel: function() { //cancel
                        $( this ).dialog( "close" );
                    }
                }
    

    So you get

        $('#msgBox').dialog({
    
    
                    autoResize: true,
                    show: "clip",
                    hide: "clip",
                    height: 'auto',
                    width: 'auto',
                    autoOpen: false,
                    modal: true,
                    position: 'center',
                    draggable: false,
                    buttons: {
                    OK: function() { //ok
                        $( this ).dialog( "close" );
                    },
                    Cancel: function() { //cancel
                        $( this ).dialog( "close" );
                    }
                }
                    open: function (type, data) {
                        $(this).parent().appendTo("form");
                    }
    
    
                });
    
    0 讨论(0)
  • 2020-12-14 20:20
    $('#msgBox').dialog({
        autoResize: true,
        show: "clip",
        hide: "clip",
        height: 'auto',
        width: 'auto',
        autoOpen: false,
        modal: true,
        position: 'center',
        draggable: false,
    
        open: function (type, data) {
            $(this).parent().appendTo("form");
        },
    
        buttons: { "OK": function() { $(this).dialog("close"); } } 
    });
    
    0 讨论(0)
提交回复
热议问题