jquery clean old dialog

好久不见. 提交于 2020-01-11 10:54:10

问题


I am trying to use UI dialog to create a modal dialog.

The dialog workscorrectly, and all is well. I close the dialog using the "X" in the corner. I tried using dialog('destroy').remove();, but then of course I can't open it again.

I think I just don't understand how to reinitialize the dialog and do not have the old values in it.

    function CreateWorkBoard()
{
    var jsmarty = WMCreateSmartyObject();
    var param =
    {
        MY_NAME1:GLOBAL_MY_NAME1,
        MY_NAME2:GLOBAL_MY_NAME2,
        LANG_NAME:LANGUAGE_NAME,
        BOARD_DIALOG_TITLE:WM_LANG_BOARD_DIALOG_BOARD_DIALOG_TITLE,
        BOARD_TITLE: WM_LANG_BOARD_DIALOG_BOARD_TITLE,
        COMMENT_TITLE:WM_LANG_BOARD_DIALOG_COMMENT_TITLE,
        MEMBERS_TITLE:WM_LANG_BOARD_DIALOG_MEMBERS_TITLE,
        CANCEL_BUTTON:WM_LANG_BOARD_DIALOG_CANCEL_BUTTON,
        REGISTER_BUTTON:WM_LANG_BOARD_DIALOG_REGISTER_BUTTON

    };
    jsmarty.assign('LANG', param);
    var divValue = WMSmartyFetch(jsmarty, 'createBoardDialog.tpl');
    document.getElementById('CREATE_DIALOG').innerHTML = divValue;
    jsmarty.clear_all_assign();
    //alert(document.getElementById('CREATE_DIALOG').innerHTML);
    //alert(divValue);

    //$.ui.dialog.defaults.bgiframe = true;
    //alert(document.getElementById('New_WorkBoard_Dialog').innerHTML);
    $('#New_WorkBoard_Dialog').dialog({

        autoOpen: false,
        height: 530,
        width:300,
        modal: true,
        resizable:false,
        buttons: {
            Cancel: function() {
                $(this).dialog('close');
                 //$('#New_WorkBoard_Dialog').dialog('destroy');
            },
            'Register board': function() {
                var board_name=document.getElementById("name");
                var comments=document.getElementById("comment");
                Createboard(board_name,comments);
                $(this).dialog('close');

            }

        },
        close: function() {

        }
    });
    $('#New_WorkBoard_Dialog').dialog('open');

}

回答1:


As Ra Yell said, is better to clean it before closing it, this way you don't have to worry about it when you open the dialog again.

$('input').val('');

The previous instruction worked for me.




回答2:


You can clear all input elements dynamically.

$("#New_WorkBoard_Dialog input[type='text']").each(function(index, element) {
    $(element).val("");
)};

If you prefer, you can clear it on close event of the dialog:

$('#New_WorkBoard_Dialog').dialog({
autoOpen: false,
height: 530,
width:300,
modal: true,
resizable:false,
buttons: {
    Cancel: function() {
        $(this).dialog('close');
         //$('#New_WorkBoard_Dialog').dialog('destroy');
    },
    'Register board': function() {
        var board_name=document.getElementById("name");
        var comments=document.getElementById("comment");
        Createboard(board_name,comments);
        $(this).dialog('close');

    }

},
close: function() {
    $("#New_WorkBoard_Dialog input[type='text']").each(function(index, element) {
        $(element).val("");
    )};
}
});



回答3:


If you want to reopen it again just use this code again:

$('#New_WorkBoard_Dialog').dialog('open');

Don't bother destroying and reinitializing the dialog. There's no need for that.



来源:https://stackoverflow.com/questions/1345584/jquery-clean-old-dialog

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!