问题描述
在我的表单中,我想使用新的 HTML5 表单类型,例如 <input type="url"/>
(
In my forms, I'd like to use the new HTML5 form types, for example <input type="url" />
(more info about the types here).
The problem is that Chrome wants to be super helpful and validate these elements for me, except that it sucks at it. If it fails the built-in validation, there's no message or indication other than the element getting focus. I prefill URL elements with "http://"
, and so my own custom validation just treats those values as empty strings, however Chrome rejects that. If I could change its validation rules, that would work too.
I know I could just revert back to using type="text"
but I want the nice enhancements using these new types offers (eg: it automatically switches to a custom keyboard layout on mobile devices):
So, is there a way to switch off or customise the automatic validation?
If you want to disable client side validation for a form in HTML5 add a novalidate attribute to the form element. Ex:
<form method="post" action="/foo" novalidate>...</form>
See https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-novalidate
这篇关于禁用 HTML5 表单元素的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!