javascript 如何在欧芹提交之前触发验证?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24817981/
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-10-28 03:22:59  来源:igfitidea点击:

How to trigger validation before submission in parsley?

javascriptjqueryvalidationparsley.js

提问by Sefier Tang

I'm now using parsley 2 to validate my form, it works fine except this problem: only after you submit your form for the first time, the validation will be triggered when you change your input, but before submission, it will do nothing.

我现在正在使用 parsley 2 来验证我的表单,它工作正常,除了这个问题:只有在您第一次提交表单后,当您更改输入时才会触发验证,但在提交之前,它什么都不做。

That said, I want to trigger validation before the first submission. How can I achieve this?

也就是说,我想在第一次提交之前触发验证。我怎样才能做到这一点?

回答by guillaumepotier

You'll need to use data-parsley-trigger="keyup"(http://parsleyjs.org/doc/index.html#psly-ui-for-form) if you want that your fields auto-validates on keyup event.

如果您希望您的字段在 keyup 事件上自动验证,您将需要使用data-parsley-trigger="keyup"( http://parsleyjs.org/doc/index.html#psly-ui-for-form)。

You could define it field by field, or on the whole form is directly in the <form>tag.

您可以逐个字段定义它,或者在整个表单上直接在<form>标签中定义。

Best

最好的