页面刷新后,输入字段将保留其值,如何防止这种情况?
<table id="post">    <tr>
        <td style="font-size: 20px;">Post Your comment</td>
    </tr>
    <tr>
        <td>Name:</td>
        <td><input type="text" id="username" name="username"></td>
    </tr>
    <tr><form id="postform" action="" method="post" name="form">
        <td>Type your message here:</td>
        <td><textarea name="text" id="text" rows="5" cols="40"></textarea></td>
    <tr>
        <td><input type="hidden" id="pageid" name="pageid" value="20"></td>
    </tr>
    <tr>
        <td><input id="submit" type="submit" value="Post Comment"  name="submit" style="width:auto;"/></td>
    </tr>
    </form>
    </tr>
</table>
该页面在刷新后仍保留在文本框和文本区域中的值。有人可以建议我克服它的方法吗?
回答:
这些值只是由客户端(网络浏览器)根据客户端历史记录自动填充的。您需要添加autocomplete="off"到表单或要关闭其的各个输入字段。
<form autocomplete="off">    ...
</form>
要么
<form>    <input autocomplete="off" />
    <input />
    <input autocomplete="off" />
    ...
</form>
无需讨厌的JS hack(不一定在所有环境下都可以)。
也可以看看:
- W3 Web Forms 2.0规范- autocomplete属性
具体问题
,您的HTML结构远非有效。我建议您通过http://validator.w3.org来传递您的页面,并相应地修正错误/警告。
以上是 页面刷新后,输入字段将保留其值,如何防止这种情况? 的全部内容, 来源链接: utcz.com/qa/410957.html






