jQuery UI Dialog Buttons from variables

后端 未结 3 1460
北海茫月
北海茫月 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 = $('

    ' + text + '

    '); 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; }

提交回复
热议问题