微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

html – 输入字段在页面刷新后保留其值,如何防止?

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

刷新后,页面在textBox和textarea中保留了价值.任何人都建议我克服它的方法吗?

解决方法

这些值仅由客户端(webbrowser)根据客户端历史记录自动填充.您需要将autocomplete =“off”添加到您要将其关闭的表单或单个输入字段.
<form autocomplete="off">
    ...
</form>

要么

<form>
    <input autocomplete="off" />
    <input />
    <input autocomplete="off" />
    ...
</form>

不需要令人讨厌的JS黑客攻击,这可能不适用于所有环境.

也可以看看:

> W3 Web Forms 2.0 specification – autocomplete attribute

与具体问题无关,您的HTML结构远非有效.我建议您通过http://validator.w3.org传递您的页面并相应地修复错误/警告.

原文地址:https://www.jb51.cc/html/231645.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐