html - 用户代理应该如何处理 HTML5 必需的属性?

标签 html required

这可能是一个有点菜鸟的问题,所以提前道歉但是...HTML5 规范是否定义了用户代理应该如何响应 HTML5 必需的属性(或者由他们决定)?换句话说,是否有任何具体的规则来定义用户代理的行为方式(例如“用户应该被提醒必填字段的存在”;“当用户提交表单时,必填的控件应该被验证并在它们不具有值的情况下显示错误消息”;等)

HTML5 规范似乎提供了一些模糊的指南,但没有具体内容。

最佳答案

规范指出,当一个 required element有一个空字符串的值:

the element is suffering from being missing

如果我们再看看 section on "constraints" (这解释了“缺失”的含义),它告诉我们:

An element can have a custom validity error message defined. Initially, an element must have its custom validity error message set to the empty string. When its value is not the empty string, the element is suffering from a custom error. It can be set using the setCustomValidity() method. The user agent should use the custom validity error message when alerting the user to the problem with the control.

将如何显示此消息的确切实现留给浏览器是有意义的,因此它们可以使其适应当前的样式和用户体验。

有浏览器如何以不同方式处理此问题的示例(屏幕截图)here ,以及浏览器兼容性信息:

enter image description here

关于html - 用户代理应该如何处理 HTML5 必需的属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12387977/

相关文章:

javascript - 下拉菜单无法选择并打开 div...我做错了什么?

iPad/iPhone 上的 Html5 表单元素 "required"不起作用

c# - 实体中可为空字段的必需属性有什么优势?

html - 在页面中显示 html 字符串

c# - 在 View 中显示来自 ViewModel 的平均值

perl - 如何使用 MooseX::Storage 使用自定义 init_arg 序列化 [required] 属性?

jquery - 仅当 Woocommerce 结帐字段可见时才需要

javascript - 如何制作Grails richui g :autocomplete field mandatory

jquery - 爆米花.js : Create a sequence of Vimeo videos

php - 更新 mysql 数据库中的一行?