禁用HTML5表单元素的验证 [英] Disable validation of HTML5 form elements

查看:163
本文介绍了禁用HTML5表单元素的验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的表单中,我想使用新的HTML5表单类型,例如< input type =url/> 关于这里的类型的更多信息)。



问题在于,Chrome想要为我提供超级帮助并验证这些元素,只不过它很糟糕。如果内置验证失败,除了获得焦点的元素外没有任何消息或指示。我使用http://预填URL元素,因此我自己的自定义验证只是将这些值视为空字符串,但Chrome会拒绝。如果我可以改变它的验证规则,那也可以。



我知道我可以恢复使用 type =text,但我希望使用这些新类型的优惠(例如:它会自动切换到移动设备上的自定义键盘布局): =https://i.stack.imgur.com/uiPln.pngalt =>



因此,是否有办法关闭或自定义自动验证? 解决方案

如果您要禁用HTML5中的表单的客户端验证,对表单元素的novalidate属性。例如:

 < form method =postaction =/ foonovalidate> ...< / form> 

请参阅 https://www.w3.org/TR/html5/sec-forms.html#element-attrdef-form-novalidate


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表单元素的验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆