如何在此页面上回发后form.reset()不起作用? [英] How come form.reset() doesn't work after postback on this page?

查看:226
本文介绍了如何在此页面上回发后form.reset()不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

班上的一名学生引起了我的注意,我没有解释 - 我找不到一个。

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.

单击提交按钮后,重置按钮不起作用。就好像浏览器在通过post请求请求资源时阻止重置。

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.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>


推荐答案

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

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.

这篇关于如何在此页面上回发后form.reset()不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆