如何更改WebKit的所需HTML表单字段的错误消息

时间:2011-03-18 16:47:35

标签: html validation forms html5 webkit

Gecko允许您使用requiredx-moz-errormessage HTML表单字段设置错误消息。

WebKit的等价物是什么?

2 个答案:

答案 0 :(得分:10)

虽然上面链接的setCustomValidity()示例有效,但它没有考虑原生HTML5验证测试,而是提供自己的自定义测试。如果您想使用HTML5中的类型匹配/模式匹配,请将setCustomValidity()oninvalid事件一起使用:

<input type="text" pattern="[a-zA-Z]+"
oninvalid="setCustomValidity('Custom Message')" />

但请记住,这不会本地化为用户的浏览器语言,也会显示无论什么是无效的(例如,如果required检查失败也会显示)

答案 1 :(得分:1)

我几乎可以肯定没有,而且看起来不会发生:http://www.w3.org/Bugs/Public/show_bug.cgi?id=10923

您可能想要查看setCustomValidity()。它对我来说似乎在Chrome中运行良好:http://olav.dk/wf2/demo/validation.asp

来源http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#dom-cva-setcustomvalidity