【问题标题】:How come form.reset() doesn't work after postback on this page?为什么 form.reset() 在此页面上回发后不起作用?
【发布时间】:2012-07-01 08:05:43
【问题描述】:

我班上的一个学生向我提出了这个问题,我对此没有任何解释——我搜索后也找不到。

点击提交按钮后,重置按钮不起作用。如果已通过发布请求请求资源,就好像浏览器会阻止重置。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <fieldset>
            <legend>User Form</legend>
            <label for="Username"></label>
            <asp:TextBox ID="Username" runat="server"></asp:TextBox>
        </fieldset>
        <asp:Button runat="server" Text="Submit" />
        <input type="button" onclick="window.document.forms[0].reset()" value="reset" />
    </div>
    </form>
</body>
</html>

【问题讨论】:

    标签: javascript webforms postback reset


    【解决方案1】:

    当您单击重置时,条目将重置为默认值。默认值是服务器在第一种情况下呈现的值,它是空字符串,但在发布后的值。 (http是无状态协议)如果您尝试编辑发布的值然后单击重置您将看到原始发布的值将被恢复。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-13
      • 1970-01-01
      • 2015-02-02
      • 1970-01-01
      • 2022-01-11
      • 2023-01-19
      相关资源
      最近更新 更多