HTML-删除错误后如何清除数据验证

发布于 2025-01-28 15:51:07 字数 367 浏览 6 评论 0 原文

我正在制作一个云页面,并在HTML中设置了一个字母数据验证,该验证良好,因为用户无法输入字母以外的任何内容。

我现在遇到的问题是,当纠正错误时,数据验证不会进行,即用户无法提交页面。

代码片段在下面。请有人可以让我转向如何纠正这一点吗?我尝试过Onblur,但它不起作用。

提前致谢!

<input  pattern="[A-Za-z\s]*" oninvalid="setCustomValidity('Please enter your first name')" name="Firstname" class="answer_box"  placeholder="Enter your first name">

I am making a cloud page and have set an alphabetic data validation in html which is working fine in that a user cannot enter anything other than letters.

The issue I am now having is that the data validation doesn't go when the error has been corrected i.e. the user cannot submit the page.

The code snippet is below. Please can someone give me a steer on how to rectify this? I have tried onblur but it didn't work.

Thanks in advance!

<input  pattern="[A-Za-z\s]*" oninvalid="setCustomValidity('Please enter your first name')" name="Firstname" class="answer_box"  placeholder="Enter your first name">

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

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

发布评论

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

评论(1

愿得七秒忆 2025-02-04 15:51:07

使用 setCustomVality()该字段无效。您必须清除验证:

oninput="setCustomValidity('')"

如本文档中所述。

With setCustomValidity() the field is invalid. You have to clear the validation:

oninput="setCustomValidity('')"

As mentioned in this documentation.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLObjectElement/setCustomValidity

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