在HTML表单中,我们可以在用户填写表单时验证文本字段 [英] In HTML form, can we validate the text fields while the user is filling in the form
问题描述
在用户输入数据时是否可以验证文本字段?
例如,如果用户在表单中选择了一个复选框,不在文本字段中输入数据,并且移动到下一个复选框,则表单应立即生成错误,提示用户输入数据先前选中的复选框。换句话说,除非每个部分
都正确完成,否则用户将无法继续进行操作(与点击提交按钮时表单末尾的错误消息)。
谢谢!
有很多插件可以帮你做到这一点。
$ b
jQuery表单验证插件:这个很好
如果您决定手动执行此操作,那么您需要使用类似以下内容:
<$ c $('input')。on('change',function(){...});
Is it possible to validate the text fields while user is entering the data? For instance, If the user selects one checkbox in the form, does not enter data in the text field, and moves on to the next checkbox, the form should generate an error immediately, prompting the user to enter data for the previously selected checkbox. In other words, user will not be able to proceed unless each section is done correctly (vs. error messages at the end of the form when the submit button is clicked)
Thank You!
There are plenty of plugins that will do this for you.
jQuery form validation plugin: This one is good
If you are determined to do it manually then you would want to use something like:
$('input').on('change', function(){...});
这篇关于在HTML表单中,我们可以在用户填写表单时验证文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!