在浏览器中单击返回或使用history.go(-1)后删除特定字段

发布于 2024-08-24 19:26:33 字数 185 浏览 0 评论 0原文

我有一个带有 capacha 的表单,如果 capacha 输入错误,提交后页面会执行“history.go(-1)”,并且所有包含 capacha 输入的字段都会返回到屏幕上,

现在我有一个 js清除这一点 - 但现在我在几个地方需要它,我想知道是否可以在返回后清除表单字段,并使用与 html 表单相关的内容或什么

感谢

i have a form with a capacha, if the capacha was entered wrong, after submit the page is doing a "history.go(-1)" and all fields include the capacha input are back on the screen

right now i have a js that clear that - but now that i need it in several places, i want to know if it possible to clear a form field after back with something related to the html form or what ever

thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

感受沵的脚步 2024-08-31 19:26:33

您是否尝试过查看缓存控制验证码图像(或页面加载它)?

Have you tried looking into cache controlling the CAPTCHA image (or the page that loads it up)?

少钕鈤記 2024-08-31 19:26:33

我认为使用“history.go(-1)”和 JavaScript 根本不是一个好主意。
您必须在服务器端验证验证码,并在服务器端选择您必须呈现的页面?再次使用验证码或下一步。

I think it's a bad idea to use "history.go(-1)" and JavaScript at all.
You must validate captcha on the server side and in server side choice that page you must render? again with captcha or next.

可遇━不可求 2024-08-31 19:26:33

我认为仅使用 html 是不可能的,需要添加一些编程。

您可以在文档的 onload 事件上调用 js 函数。

函数可以是这样的:

function resetfields()
{
  $("input[type=text]").val("");
  $("textarea").val(""); // if any textarea
}

你也可以在这个函数中使用一些ajax来每次都获取一个新的验证码。

您可以将此函数放在母版/标题页中,这样您就不需要将其复制到所有页面(因为您可能需要使选择器更精确)。

I dont think its possible with only html, need to add some programming.

You can have js function that is called on onload event of document.

function can be like this:

function resetfields()
{
  $("input[type=text]").val("");
  $("textarea").val(""); // if any textarea
}

And you can also use some ajax in this function to get a new captcha every time.

you can place this function in your master/header page, so that you don't need to copy it to all pages (for that you may need to make selector more precise).

她说她爱他 2024-08-31 19:26:33

另一种选择是您可以在每次访问页面时重命名表单字段。将时间戳附加到名称。这样浏览器就不会自动填充它。您可能需要稍微调整后端代码来解决这个问题。

Another option is that you can rename the form field with every visit to the page. Append a timestamp to the name. That way the browser won't autofill it. You probably will have to adjust your backend code slightly to account for this.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文