jQuery UI Dialog Buttons from variables

后端 未结 3 1452
北海茫月
北海茫月 2020-12-14 17:10

I have variables holding the translated labels for buttons inside a jquery ui dialog.

I cannot fill the button array key with the variable itself, and can\'t find an

相关标签:
3条回答
  • 2020-12-14 17:47

    I know this is 4 years old, but it is the top result for an issue I have been having. Here was the results of my labor.

    Simply call the function in a mouse or keyboard event, reference a function (without parentheses), define the buttons or set blank, set a title, and set the text to be displayed.

    function confirmDialogue(fn, value, ok, cancel, title, text){
        if (typeof ok == "undefined" || ok == ""){ok = "Ok";}
        if (typeof cancel == "undefined" || cancel == ""){cancel = "Cancel";}
        var buttonsOpts = {};
        buttonsOpts[ok] = function() {fn(value);$( this ).dialog( "destroy" );}
        buttonsOpts[cancel] = function() {$( this ).dialog( "destroy" );}
    
        var NewDialog = $('<div id="dialogConfirm"><p>' + text + '</p></div>');
        NewDialog.dialog({
            title: title,
            dialogClass: "dialogue",
            modal: true,
            height: "auto",
            width: "auto",
            show: true,
            hide: true,
            close: function(){$(this).dialog('destroy');},
            buttons: buttonsOpts
        });
        return false;
    }
    
    0 讨论(0)
  • 2020-12-14 17:57
    jQuery('#bar').dialog({
       buttons : [
           {
            text: translations.ok,
            click: function(){}
           },
           {
            text: translations.cancel,
            click: function(){}
           },
       ]
    });
    
    0 讨论(0)
  • 2020-12-14 18:03

    You can try this, may be it helps:

    var buttonsOpts = {}
    buttonsOpts[translations["ok"]] = function ....
    buttonsOpts[translations["cancel"]] = function ....
    jQuery('#bar').dialog({
       buttons : buttonsOpts
    });
    

    Hope it helps!

    0 讨论(0)
提交回复
热议问题