jquery循环形式检查所有空字段然后执行一个函数 [英] Jquery loop form to check for all empty fields then execute a function

查看:107
本文介绍了jquery循环形式检查所有空字段然后执行一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图循环表单来检查空字段,然后执行和运行。我目前正在使用下面这样的东西,我发现在这个网站上,但是发生了什么,每个循环检查1字段,并看到1不是空的,仍然执行else功能。我想我需要一次检查所有内容,然后执行下一个功能。

I'm trying to loop form to check for empty field and then execute and function. I'm currently using something like this below that I found on this website but what is happening that the each loop check 1 field and see 1 that not empty and still execute else function. I think I need to check all at once then execute next function. How could I achieve this?

if($('.enter-info--ownerInfo .req').val() != "") {
   alert("Empty Fields!!")
    } else {
    run this function
    }  

感谢...

Thanks...

推荐答案

使用过滤,很简单:

Use filtering, it is easy:

var anyFieldIsEmpty = $("form :input").filter(function() {
        return $.trim(this.value).length === 0;
    }).length > 0;

if (anyFieldIsEmpty) {
    // empty fields
}

DEMO: http://jsfiddle.net/Lz9nY/

这篇关于jquery循环形式检查所有空字段然后执行一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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