jQuery验证插件:强制对空字段进行验证 [英] jQuery Validation PlugIn : Forcing Validation on empty Field

查看:87
本文介绍了jQuery验证插件:强制对空字段进行验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有字段的表格.第一个是必需的.

I have a form with tho fields. The first one is required.

步骤1.提交表单时,出现预期的错误. 步骤2.然后,如果我在字段上输入文本,则错误文本将很清楚,这是完美的.

step 1. When I submit the form, I get the error as expected. step 2. Then if I enter a text on the field, the error text is clear, which is perfect.

我唯一担心的是,如果我删除输入的文本,将该字段留空,则验证不会启动!

My only concern is that if I remove the text entered, leaving the field empty, the validation don't fire up!

有没有一种方法可以强制对空字段进行验证?还是至少使用在第2步中使用的回调函数?验证失败后,我想执行一些任务.

Is there a way to force validation on empty fields? or at least use the callback function that is used on step 2? I want to perform some tasks when a validation fails.

目标是每次验证失败时更改标签的类别.

The goal is to change the class of a label every time the validation fails.

推荐答案

我用过

onkeyup : function(element){
        if ($(element).valid()==0) {
            $(element).prev().removeClass();
            $(element).prev().addClass("status_form_warning");    
        }

这篇关于jQuery验证插件:强制对空字段进行验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆