jQuery中的空字段验证 [英] empty field validation in jquery

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

问题描述

我有3个文本字段.

第一个字段是唯一的必填字段,但是如果第二个字段不为空,则第一个和第三个文本字段不应为空.

The first field is the only mandatory field, but if the second field is not empty the first and third text field should not be empty.

如何在jquery中执行此验证?

How to do this validation in jquery?

推荐答案

简单:

var set = $('input[type="text"]');
if(set.eq(0).val().length == 0 || (set.eq(1).val().length > 0 && set.eq(2).val().length == 0)) {
   //throw error
} 

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

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