Javascript 弹出窗口无法正确加载。每次都需要刷新页面

Javascript 弹出窗口无法正确加载。每次都需要刷新页面,javascript,jquery,asp.net-mvc,Javascript,Jquery,Asp.net Mvc,有一个链接: <div > <a href="#" class="newComment" onclick="bindAddSlots()">Add Details</a> </div> 查看代码:- <div id="dvSchedulingProfile" style="display: none"> @Html.ValidationSummary(true) <table width=

有一个链接:

<div >
    <a href="#" class="newComment" onclick="bindAddSlots()">Add Details</a>
</div>
查看代码:-

<div id="dvSchedulingProfile" style="display: none">
        @Html.ValidationSummary(true)
        <table width="100%" height="75%" class="someclass">

             <tr id="AddVisitType">
                <td  class="black_label">
                    @Html.HiddenFor(m => m.SchedulingProfileDetails.Id)
                    @Html.Label("Visit Type"):<span class="star">*</span>
                </td>
                <td  style="font-size: 12px;">
                    @Html.DropDownList("ddlVisitType", new SelectList((VisitTypeBo.LoadAll().OrderBy(x => x.VisitTypeName)), "VisitTypeName", "VisitTypeName"), new { @style = "width:250px;color:black" })
                <br/>
                </td>
            </tr>

            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblAnnualVisitType"
                    align="left">
                    @Html.Label("lblAnnualVisitType", "Visit Type is required.")
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
            </tr>
            <tr>
                <td class="black_label">
                    @Html.Label("Patient Slots(NP)"):<span class="star">*</span>
                </td>
                <td style="font-size: 12px;">
                    @Html.TextBox("txtNP", null, new { @style = "width:250px;", maxlength = 11 })
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNP" align="left">
                    @Html.Label("lblNP", "NP is required.")
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNPNumeric" align="left">
                    @Html.Label("lblNPNumeric", "Only Numeric values are allowed.")
                </td>
            </tr>
            <tr>
                <td class="black_label">
                    @Html.Label("Time Slots(NS)"):<span class="star">*</span>
                </td>
                <td style="font-size: 12px;">
                    @Html.TextBox("txtNS", null, new { @style = "width:250px;", maxlength = 11 })
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNS" align="left">
                    @Html.Label("lblNS", "NS is required.")
                </td>
                <td style="color: Red; font-size: 12px; display: none;" class="lblNSNumeric" align="left">
                    @Html.Label("lblNSNumeric", "Only Numeric values are allowed.")
                </td>
            </tr>
            <tr>
                <td height="5">
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td >
                    <input type="button" value="" class="save_bt" onclick="return SaveDetails()" style="margin-left:70PX;"/>
                </td>
            </tr>
        </table>
    </div>

@Html.ValidationSummary(true)
@HiddenFor(m=>m.SchedulingProfileDetails.Id)
@Html.Label(“访问类型”):*
@DropDownList(“ddlVisitType”,新选择列表((VisitTypeBo.LoadAll().OrderBy(x=>x.VisitTypeName)),“VisitTypeName”,“VisitTypeName”),新{@style=“width:250px;color:black”})

@Label(“lblAnnualVisitType”,“需要访问类型”) @Html.Label(“患者时段(NP)”):* @TextBox(“txtNP”,null,新的{@style=“width:250px;”,maxlength=11}) @Label(“lblNP”,“需要NP”) @Label(“lblNPNumeric”,“仅允许数值”) @Html.Label(“时隙(NS)”):* @TextBox(“txtNS”,null,新的{@style=“width:250px;”,maxlength=11}) @标签(“lblNS”,“需要NS”) @Label(“lblNSNumeric”,“仅允许使用数值”)

现在的问题是,当页面加载时,我点击链接,弹出窗口就会出现,但要让弹出窗口再次出现,我需要刷新代码,所有浏览器中的问题都是一样的。我一次又一次地调试代码,但是没有错误发生,我完全糊涂了,所以请有人帮我解决这个问题。提前感谢。

将对话框附加到表单的第一个元素到底需要什么? 如果你去掉那条线,我想它会很好用的


因为,第一次它工作正常,因为只有一个id为
dvSchedulingProfile
的元素,并且在显示对话框后,您会立即将相同的元素再次添加到表单的第一个元素中,所以下次会有两个id相同的元素,现在jquery对话框不起作用了,因为它找不到具有给定id的单个元素。

问题是,当我们关闭对话框时,它只会关闭,但我们需要销毁它,这样表单就不会与它有任何剩余的关联。因此,我们需要一些额外的代码行来决定关闭弹出窗口时要做什么

var dclg=$("#dvSchedulingProfile")
     dclg.dialog(
     {
         resizable: false,
         draggable: true,
         modal: true,
         title: "ADD Details",
         width: "400",
         height: "460",
         close: function () {
          dclg.dialog("destroy");
          dclg.hide();
          }
     });

你是说一旦你关闭弹出窗口,你就不能再打开它,直到你重新加载整个页面?这就是问题所在。那么你用什么代码关闭弹出窗口呢?我有一种感觉,这就是你的问题所在。你似乎在追加,但我找不到删除。也许你的问题就在那里?关闭弹出窗口的时候,我有一个保存按钮的onclick方法中的代码。我尝试删除该行,但问题仍然存在
var dclg=$("#dvSchedulingProfile")
     dclg.dialog(
     {
         resizable: false,
         draggable: true,
         modal: true,
         title: "ADD Details",
         width: "400",
         height: "460",
         close: function () {
          dclg.dialog("destroy");
          dclg.hide();
          }
     });