带有必需和禁用元素的Html5表单验证

我意识到你永远不应该禁用一个元素并且也需要它,因为如果它被禁用,用户怎么能使它有效?

但是,我有一个< select>我希望用户可以选择的产品.当他们选择其中一个产品时,另一个< select>仅当产品具有一个或多个型号时,才会填充,启用和要求产品型号.否则,禁用并清空模型选择.

虽然我喜欢认为我的代码是完美的,但我可以做到这样,模型下拉列表永远不会被禁用并且同时需要,我并不完美.那么,表格是否能够通过< select>提交.那是禁用和必需的?

更新

来自w3.org:

Constraint validation: If the element is required,and its value IDL attribute applies and is in the mode value,and the element is mutable,and the element’s value is the empty string,then the element is suffering from being missing.

查看具体的“可变”意味着什么.

A form control can be designated as mutable.

Note: This determines (by means of definitions and requirements in this specification that rely on whether an element is so designated) whether or not the user can modify the value or checkedness of a form control,or whether or not a control can be automatically prefilled.

选择没有值,因此它由它的选项决定.

The select element does not have a value; the selectedness of its option elements is what is used instead.

所以,我认为这意味着如果< select>元素被禁用和要求,表格可以被视为有效吗?

解决方法

http://www.w3.org/TR/html5/forms.html#enabling-and-disabling-form-controls:-the-disabled-attribute

Constraint validation: If an element is disabled,it is barred from constraint validation.

http://www.w3.org/TR/html5/forms.html#barred-from-constraint-validation

A submittable element is a candidate for constraint validation except when a condition has barred the element from constraint validation.

最后,从约束验证步骤列表http://www.w3.org/TR/html5/forms.html#constraint-validation

3.1: If field is not a candidate for constraint validation,then move on to the next element.

这意味着,当检查表单有效性时,禁用的元素将被“传递”.

它不会触发任何错误,并且对其所属表单的验证状态没有任何影响.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


HTML5和CSS3实现3D展示商品信息的代码
利用HTML5中的Canvas绘制笑脸的代码
Html5剪切板功能的实现
如何通过HTML5触摸事件实现移动端简易进度条
Html5移动端获奖无缝滚动动画实现
关于HTML5和CSS3实现机器猫的代码
HTML5使用DOM进行自定义控制
使用HTML5 Canvas绘制阴影效果的方法
使用PHP和HTML5 FormData实现无刷新文件上传
如何解决HTML5 虚拟键盘出现挡住输入框的问题
HTML5中div和section以及article的区别分析
html5和CSS 实现禁止IOS长按复制粘贴功能
html5 touch事件实现触屏页面上下滑动
canvas 模拟实现电子彩票刮刮乐的代码
HTML5 Plus 实现手机APP拍照或相册选择图片上传的功能
Android自定义环形LoadingView效果
HTML5 canvas绘制五角星的方法
html5使用html2canvas实现浏览器截图
使用Canvas处理图片的方法介绍
利用Canvas模仿百度贴吧客户端loading小球的方法