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

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

问题描述

我班上的一个学生让我注意到了这一点,但我没有解释——而且我在搜索后找不到.

点击提交按钮后,重置按钮不起作用.如果资源是通过 post 请求请求的,就好像浏览器会阻止重置.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="服务器"><title></title><身体><form id="form1" runat="server"><div><字段集><legend>用户表单</legend><label for="用户名"></label><asp:TextBox ID="用户名" runat="服务器"></asp:TextBox></fieldset><asp:Button runat="server" Text="Submit"/><input type="button" onclick="window.document.forms[0].reset()" value="reset"/>

</表单>

解决方案

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

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

解决方案

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天全站免登陆