jQuery UI dialog button text as a variable

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

    1. The button option in jQuery UI dialog accepts objects and arrays.
    2. The buttons are instances of the button widget. Use the API instead of manipulating the buttons yourself.

    $(function() {
      // using textbox value instead of variable
      $("#dialog").dialog({
        width: 400,
        buttons: [
          { text: $("#buttonText0").val(), click: function() { $(this).dialog("close"); } }, 
          { text: $("#buttonText1").val(), click: function() { $(this).dialog("close"); } }
        ]
      });
      $("#updateButtonText").on("click", function() {
        var $buttons = $("#dialog").dialog("widget").find(".ui-dialog-buttonpane button");
        console.log($buttons.get());
    
        $buttons.eq(0).button("option", "label", $("#buttonText0").val());
        $buttons.eq(1).button("option", "label", $("#buttonText1").val());
    
        // few more things that you can do with button widget
        $buttons.eq(0).button("option", "icons", { primary: "ui-icon-check" });
        $buttons.eq(1).button("disable");
    
        $("#dialog").dialog("open");
      });
    });
    @import url("https://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.min.css");
    
    
    
    

    Proceed?

提交回复
热议问题