jQuery UI dialog button text as a variable

后端 未结 12 1782
隐瞒了意图╮
隐瞒了意图╮ 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:08

    What you can do is assign the button in the dialog an ID and then manipulate it using standard jQuery.

    $("#dialog_box").dialog({
        autoOpen: false,
        modal: true,
        resizable: false,
        buttons: [{
            text: "Ok",
            "id": "btnOk",
            click: function () {
                //okCallback();
            },
    
        }, {
            text: "Cancel",
            click: function () {
                //cancelCallback();
            },
        }],
        close: function () {
            //do something
        }
    });
    

    Set button text:

     var newLabel = "Updated Label";
     $("#btnOk").html(''+ newLabel +'')
    

提交回复
热议问题