- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
阅读一个使用 MVC 的网站源代码时,我很难理解其中的一些内容。
View 的代码片段:
function submitForm (action) {
var forms = document.getElementById('form')
forms.action = action
if (forms.checkValidity()) {
forms.submit()
} else {
alert('There is still an empty field')
}
}
如果表单缺少某些输入,我想执行一些代码。
最佳答案
checkValidity()
是一个 HTML5 方法并且
When the checkValidity() method is invoked, if the element is a candidate for constraint validation and does not satisfy its constraints, the user agent must fire a simple event named invalid that is cancelable (but in this case has no default action) at the element and return false. Otherwise, it must only return true without doing anything else.
请详细了解如何使用表单验证约束here .您可以使用、自定义甚至构建自定义验证方法的有用方法有很多。
您还可以在 w3schools 中找到基本解释和示例.希望这会有所帮助。
关于javascript - 如何使用 HTML form.checkValidity()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45789010/
我有三列表单,第一列有输入字段,接下来的两列有复选框,如果我提交我的表单而不输入任何内容,那么页面顶部的第二列和第三列会出现警报,然后第 1 列会出现警报消息。这里如何使用这个方法?
有没有办法让 checkValidity() 只对表单的一部分起作用?例如,检查 keyUp 事件的有效性?还是严格要求完整的表单提交? 如果那样不行,是否有任何第三方插件可以作为此类情况的垫片? 我
我有一个带有按钮的表单,该按钮是一个链接(带有“to”属性),并且我使用 checkValidity() 来使用必需的属性,但是如果我使用 to={{pathname...} } 它更改为链接而不进行
出于某些原因,当我在表单上使用 checkValidity() 时,失败的输入不会被标记为无效。 方法是这样调用的: var result=$("#myForm")[0].checkValidity(
当我在输入元素上使用 .checkValidity() 并返回 false 时,我如何获得失败的原因? 我知道我可以使用 ValidityState interface并检查每个可能的失败,但是那些只
如果通过 JavaScript 设置值,HTML5 checkValidity()/reportValidity() 方法似乎不起作用。 考虑这个例子(JSFiddle): Set Is valid
第一次发帖,请多多关照。我正在尝试自学如何为本地俱乐部编写响应式网站。有没有办法使用 bootstrap 4 表单验证方法检查两个密码字段是否相同并相应地出错?我可以在服务器端执行此操作,但由于我正在
我有一个简单的表格如下: Line 1: Fill Line 2? Lin
给定以下文档: 不填写输入,运行: document.querySelector('input').checkValidity() 返回 true。 因为空输入不匹配[a-z],为什么是HTML5
当我们尝试提交 HTML5 表单时,如果一个或多个必填字段缺少值或发生其他错误(类型或长度不匹配),它会阻止表单提交。 UI 更新为突出显示的无效字段,并聚焦第一个无效字段。此外,第一个无效字段附有一
我刚刚发现了 JavaScript Validation API checkValidity() 函数。 caniuse.com 表示此 API 在 Firefox 和 Chrome 中可用。我不需要
此处为 IE11 问题,可在其他浏览器中使用(见图)。 我有一个带有一组单选按钮的表单。 单选按钮具有required属性 当我加载页面并在表单上运行 checkValidity() 函数时,它返回
HTML 和 JS 新手。我一直在试图弄清楚为什么当我没有在字段中输入任何名称时我没有收到任何通知。当前外观的快速视频:VIDEO of entering name 我的代码正在查找 HTML:
我在 ajax 表单提交中使用 jQuery 的 checkValidity(),一切正常,直到表单有一个 select 元素。 例如,我有一个页面根据用户选择的行数显示数据。 (选择多少行数据)..
阅读一个使用 MVC 的网站源代码时,我很难理解其中的一些内容。 View 的代码片段: function submitForm (action) { var forms = document.g
我正在尝试使用这样的 checkValidity 函数验证表单的输入 let inputs = document.getElementsByTagName('input'); inpu
我注意到输入元素验证有两种方法: element.checkValidity()。 element.validity.valid。 我知道 validity 是一个对象,而 checkValidity
我正在尝试对模糊的数字输入字段执行简单的 checkValidity,但无法使其正常工作。这在 Chrome 中有效吗?例如: 或 似乎什么都不做。但是,在控制台中, $("#x")[0].che
我正在尝试使用表单方法 checkValidity()。 http://html5test.com/告诉我我的浏览器 (Chrome) 支持表单级 checkValidity 方法。 但是,使用 js
问题的简短版本 有没有办法用 Javascript 触发原生浏览器表单验证错误反馈? 问题的详细版本 当尝试提交具有用户未填写的必填输入字段的表单时,现代浏览器会自动处理验证,并在发现错误的输入字段处
我是一名优秀的程序员,十分优秀!