【问题标题】:Every button submits in ASP [duplicate]每个按钮在 ASP 中提交 [重复]
【发布时间】:2014-09-29 14:10:11
【问题描述】:

无论我在做什么,当我在一个表单中有两个按钮时,即使其中一个显然不是提交按钮而另一个是提交类型输入,它们总是都提交表单。我有这样一段代码:

       <form method="POST">
            <tr class="record">
                /* This one submits */
                <td><button onclick="location.href='editStudent.cshtml?id=@row.No'">Edit record</button></td>

                /* And so does this one */
                <td><input type="submit" value="Delete" /></td>
                </tr>
           </form>

我知道我不应该在中间表中创建表单,但这不是重点。请告诉我我做错了什么,因为我已经解决这个问题太久了。

【问题讨论】:

  • 您的 HTML 无效。您不能将表格行作为表单的子项。

标签: php asp.net forms


【解决方案1】:

正如您在http://www.w3schools.com/tags/tag_button.asp 看到的那样,您应该定义按钮元素的 type 属性以避免意外行为

所以如果你不想弄乱javascript,你可以试试这个 &lt;button type="button" onclick="location.href='editStudent.cshtml?id=@row.No'"&gt;Edit record&lt;/button&gt;

【讨论】:

    猜你喜欢
    • 2013-12-06
    • 1970-01-01
    • 2015-05-04
    • 2010-12-26
    • 2016-10-10
    • 2015-09-20
    • 1970-01-01
    相关资源
    最近更新 更多