Html HTML5 的 novalidate 和 formnovalidate 属性有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11761202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 02:00:26  来源:igfitidea点击:

What's the difference between novalidate and formnovalidate attributes of HTML5?

formshtml

提问by Bagata

From w3c schools we have these definitions:

从 w3c 学校,我们有以下定义:

novalidate:

无验证

When present, it specifies that the form-data (input) should not be validated when submitted.

当存在时,它指定提交时不应验证表单数据(输入)。

formnovalidate:

表单验证

When present, it specifies that the element should not be validated when submitted.

当存在时,它指定元素在提交时不应进行验证。

Does it make any difference using formnovalidatein the submit buttoninsted of using novalidatein the form?

提交按钮中使用formnovalidate与在表单中使用novalidate 有什么区别吗?

(I really don't get the difference)

(我真的不明白区别)

回答by stopsatgreen

novalidateis applied to the form, and prevents it from being validated; formnovalidateis applied to a submit button, and overrides the novalidateoption, if present; it means 'submit this form without validating, regardless of the general form setting'.

novalidate应用于表单,并阻止它被验证;formnovalidate应用于提交按钮,并覆盖novalidate选项(如果存在);它的意思是“无论一般的表单设置如何,都无需验证即可提交此表单”。

The example given in the spec is when a user is saving data rather than publishing it; the data might be incomplete and invalid, but doesn't require validation to be saved.

规范中给出的示例是当用户保存数据而不是发布数据时;数据可能不完整和无效,但不需要保存验证。