this.form.submit() 在删除代码后仍然会触发

this.form.submit() still fires after code is removed

本文关键字:代码 删除 submit form this      更新时间:2023-09-26

问题:我想做的是在退出已添加到视图中的文本框时触发表单提交事件。

详:我在 MVC 应用程序中有一个视图,我在视图底部添加了三个文本框。 在此添加之前,我有一个 Html 帮助程序文本区域,当我跳出它时,它会触发 this.form.submit:

<%=Html.TextAreaFor(r => r.Notes, new { @class = "textAreaNoScroll", @onblur = "this.form.submit();"} })%>

在更改之前,这是页面底部的最后一个控件。 我已经@onblur削减了代码...并将其粘贴到现在的最后一个控件中:

<%=Html.TextBoxFor(acc => acc.AccountNumber, new { @onblur = "this.form.submit();"}) %>

但是当我现在调试时,视图仍然在 id 为"r.Notes"的文本区域上进行提交。

修复:首先,我从浏览器(Chrome(检查"查看源代码"中的标记。 更改是正确的。 我清除了浏览器缓存,但这没有区别。 下面是相关代码段:

 <asp:Panel ID="pnlProcessingInstructions" runat="server">            
            <table class="displayBox-topBottom">
                <tr>
                    <td class="labels displayInput_noWidth">Processing Notes</td>
                    <td class="labels displayInput_noWidth">Instructions</td>
                </tr>
                <tr>
                    <%if (Model != null && Model.PaymentDayId != -1)
                      { %>
                        <td><%=Html.TextAreaFor(r => r.ProcessingNotes, new { @class = "textAreaNoScroll" })%></td>
                    <%}
                      else
                      {%>
                        <td><%=Html.TextAreaFor(r => r.ProcessingNotes, new { @class = "textAreaNoScroll" })%></td>
                    <%}%>
                    <td><%=Html.TextAreaFor(r => r.Notes, new { @class = "textAreaNoScroll" })%></td> <!-- FORMER LAST CONTROL -->
                </tr>              
                <tr>
                    <td><span id = "ProcessingCharsLeft" class="smallerFont">1,000</span> characters left</td>
                    <td><span id = "CharsLeft" class="smallerFont">1,000</span> characters left</td>
                </tr>
            </table>
            </asp:Panel>
           </fieldset>
           <fieldset>
        <legend class="labels"> Payment Details</legend>
          <asp:Panel ID="pnlPaymentDetails" runat="server">            
            <table class="displayBox-topBottom">
                <tr>
                    <td class="labels displayInput_noWidth">Institution</td>
                    <td class="labels displayInput_noWidth">Transit</td>
                    <td class="labels displayInput_noWidth">Account Number</td>
                </tr>
                <tr>
                    <td><%=Html.TextBoxFor(i => i.Institution) %></td>
                    <td><%=Html.TextBoxFor(tr => tr.TransitNumber) %></td>
                    <td><%=Html.TextBoxFor(acc => acc.AccountNumber, new { @onblur = "this.form.submit();"}) %></td> <!-- NEW LAST CONTROL -->
                </tr>
                </table>
               </asp:Panel>  

它永远不会超过"r.Notes",并且表现得好像"this.form.submit"仍然是控件的一部分。 同样,我已经清除了缓存并重新生成了我的解决方案。"this.form.submit(("如何在代码不存在的控件上触发?

好的,我想通了。 上一页使用相同的模型元素"r.Notes"。 此页面具有form.submit事件,这就是触发我正在编辑的页面上提交的原因。 我将textareafor重命名为html.textArea控件,并将其重命名为MyNotes作为id,但它没有提交。