javascript 第二次打开jquery对话框时如何只刷新它的内容

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13683424/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 19:27:56  来源:igfitidea点击:

How to refresh only the contents of jquery dialog while opening it for the second time

javascriptjqueryasp.nethtmljquery-dialog

提问by Xavier

i am opening a jquery dialog in a click function. But if i close the dialog and open it for the second time, the contents inside the dialog remains the same.. I need the text boxes inside the dialog to be empty while i open it for the consecutive times..

我正在单击功能中打开一个 jquery 对话框。但是如果我关闭对话框并第二次打开它,对话框内的内容保持不变..我需要对话框内的文本框在我连续打开它时为空..

This is my aspx code:

这是我的aspx代码:

<div>
<span id="id_PrivateSpace" style="color: #88b807; margin-left: 839px;
                            margin-top: -12px; cursor: pointer; display: block">Create</span>
</div>


<div id="thedialog" style="display: none; overflow: hidden">
                    <table id="table" style="border-spacing: 7px 7px; margin-left: 5px">
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Private Space Name </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_spacename" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Private Space Description </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_spacedesc" TextMode="MultiLine" runat="server" />
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">Users </span>
                            </td>
                            <td>

                                <input type="text" id="txt_users" />
                            </td>
                            <td>
                                <asp:Button ID="btn_addusers" Text="Add" Style="margin-left: 10px;" runat="server" />
                            </td>
                            <td rowspan="5">
                                <table id="users_grid" align="left">
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <span class="SubHeading" style="font-size: 10pt;">DL </span>
                            </td>
                            <td>
                                <asp:TextBox ID="txt_Add_dl" TextMode="MultiLine" runat="server" />
                            </td>
                        </tr>
                    </table>
                    <input type="button" id="Btn_Submit" value="Create" style="margin-left: 335px; margin-top: 35px;"
                        runat="server" />
                </div>

This is my js code:

这是我的js代码:

 $("#thedialog").dialog({
                autoOpen: false,
                title: 'Create Private space',
                modal: true,
                position: 'center',
                width: 900

            });


            $('#id_PrivateSpace').click(function() {
                $('#thedialog').dialog('open');
                return false;
            });

what should i add to refresh only the contents of the dialog?

我应该添加什么来只刷新对话框的内容?

采纳答案by Akhil Sekharan

I guess you can try:

我想你可以试试:

$('#id_PrivateSpace').click(function() {
    $("#thedialog").find('input:text, textarea').val('').attr('placeholder','Enter some value');
    $("#thedialog").find('select').val('');//you need to have and option like <option value="">Please Select</option> in your select options list
    $('#thedialog').dialog('open');
    return false;
}); 

And for your aspx Dropdownlist make sure you set AppendDataBoundItems to true; and set the OnDataBinding event

对于您的 aspx 下拉列表,请确保将 AppendDataBoundItems 设置为 true;并设置 OnDataBinding 事件

<asp:DropDownList id="myDdl" runat="server" OnDataBinding="Ddl_Databinding" >
</asp:DropDownList>

And in your code behind, Add:

protected void Ddl_Databinding(object sender, EventArgs e)
{
    DropDownList ddl = (DropDownList)sender;
    ddl.Items.Add(new ListItem("Please Select", ""));
}

回答by Akhil Sekharan

Add the following function on close to destroy the particular instance of your jquery dialog:

在 close 上添加以下函数以销毁 jquery 对话框的特定实例:

close: function()
    {
        $(this).dialog('close');
        $(this).dialog('destroy');
        $(this).html("");
    },

This is the code I had to use having similar problem when I was creating dialogs on the fly.

这是我在动态创建对话框时必须使用的代码,但遇到类似问题。

回答by Ibrahim AshShohail

$('#id_PrivateSpace').click(function() {
  $("#thedialog input[type='text']").val('');
  $("#thedialog textarea").html('');
  $('#thedialog').dialog('open');
  return false;
}); 

回答by madhu

Try,

尝试,

<form id="myform>
<div id =thedialog> ....... </div>
</form>

When you close the dialog box, call the below function

关闭对话框时,调用以下函数

    document.getElementById("form1").reset();