Add a button to a dialog box dynamically

后端 未结 2 1189
猫巷女王i
猫巷女王i 2021-02-06 00:52

Is there any way to add a button to a dialog box in jquery ui dynamically.

I tried using: $(this).add(\"button\");

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 01:40

    This is answered right on the jQuery UI page for dialog... http://jqueryui.com/demos/dialog/ (click "Options" tab, then the link for "Buttons")

    "Get or set the buttons option, after init"...

    $( ".selector" ).dialog( "option", "buttons", { 
     "Ok": function() { $(this).dialog("close"); } 
    } );
    

    Just add the appropriate selector (whatever element you're using as the dialog), and you should be good to go.

提交回复
热议问题