Difference Between .dialog(“close”) and .dialog(“destroy”)

后端 未结 3 805
醉酒成梦
醉酒成梦 2021-02-12 14:28

What is the difference between .dialog(\"close\") and .dialog(\"destroy\") in jquery-ui?

I have a script where the previous developer had used

3条回答
  •  灰色年华
    2021-02-12 15:12

    Remember if you are using the dialog for forms input, that destroying it will NOT remove your input, so if you are validating with the :input pseudo selector, the elements you 'destroyed' will be validated. This is where .remove() comes in handy.

    You can add a custom close event that destroys your dialog and removes any form inside it to prevent further validation of it.

    $dialog = $("#your_dialog_id");
    $dialog.dialog('option', {
        title: "title",
        close: function (event, ui) {
            $dialog.find("form").remove();
            $dialog.dialog('destroy');
        }
    });
    

提交回复
热议问题