jQuery UI dialog button text as a variable

后端 未结 12 1781
隐瞒了意图╮
隐瞒了意图╮ 2020-12-13 01:21

Can anyone tell me how can i use a variable for button text in jQuery UI dialog? I want to make a dynamic button name.

12条回答
  •  离开以前
    2020-12-13 02:06

    Yes completely possible with inline behaviour:

    1. Create Dialog class with two setter method, setYesButtonName() and setNoButtonName.

            function ConfirmDialog() {
                var yesButtonName = "Yes";
                var noButtonName = "No";
                this.showMessage = function(message, callback, argument) {
                    var $dialog = $('
    ') .html(message) .dialog({ modal: true, closeOnEscape: true, buttons: [ { text:yesButtonName, click: function() { if (callback && typeof(callback) === "function") { if (argument == 'undefined') { callback(); } else { callback(argument); } } else { $(this).dialog("close"); } } }, { text:noButtonName, click: function() { $(this).dialog("close"); } } ] }); $dialog.dialog("open"); }; this.setYesButtonName = function(name) { yesButtonName = name; return this; }; this.setNoButtonName = function(name) { noButtonName = name; return this; }; }

    1. Create Object of ConfirmDialog class.

       this.CONFIRM_DIALOG = new ConfirmDialog();
      
    2. Call method on any event, let's say onclick()

      OK_DIALOG.setYesButtonName('Wana Marry').showMessage('Worst Idea!!');
      

    Job Done!!

提交回复
热议问题