jQuery验证(至少一个字段具有文本) [英] jquery validate (at least one field has text)

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

问题描述

所以我有此页面,其中有多个TextAreas(asp.net mvc).
我需要验证这些字段中至少有一个包含文本. 我该如何使用jQuery?

So i have this page wich has several TextAreas (asp.net mvc).
I need to validate that at least one of those fields has text in it. How can i do that with jquery?

<%= Html.TextArea("taMetodologia",Model.Enmienda.Detalles.EnmiendaMetodologia, 8, 70,new {@class = "Especificaciones"}) %>

这是我拥有的textAreas的示例!

That's an example of the textAreas i have!

预先感谢;)

推荐答案

假定您未使用validate插件,并且所有文本区域都具有"Especificaciones"类,则可以在该类上使用过滤器.

Assuming you are not using the validate plugin and all the textareas have the "Especificaciones" class, you could use a filter on the class.

如果以下内容的长度大于0,则至少一个文本区域中具有值.

If the length of the following is greater than 0, then at least one of the textareas had a value in it.

$(".Especificaciones").filter(function(){
    return $(this).val() != "";
}).length;

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

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