最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How come form.reset() doesn't work after postback on this page? - Stack Overflow

programmeradmin6浏览0评论

A student in my class brought this to my attention, and I didn't have an explanation for it-- and I couldn't find one after searching.

After clicking the submit button, the reset button does not work. It's as if the browser prevents reset if the resource has been requested via post request.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ".dtd">

<script runat="server">

</script>

<html xmlns="">
<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>

A student in my class brought this to my attention, and I didn't have an explanation for it-- and I couldn't find one after searching.

After clicking the submit button, the reset button does not work. It's as if the browser prevents reset if the resource has been requested via post request.

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

<script runat="server">

</script>

<html xmlns="http://www.w3/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>
Share Improve this question asked Jun 29, 2012 at 19:22 ek_nyek_ny 10.3k8 gold badges51 silver badges60 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

When you click reset then the entries are reset to the default values. Default values are values which were rendered by the server in the first case it was empty string but after post the posted value. (http is stateless protocol) If you try to edit the posted value then click reset you will see that the originally posted value will be restored.

发布评论

评论列表(0)

  1. 暂无评论