jQuery 验证(至少一个字段有文本)
我的这个页面有几个 TextAreas (asp.net mvc)。
我需要验证这些字段中至少有一个包含文本。 我怎样才能用 jQuery 做到这一点?
<%= Html.TextArea("taMetodologia",Model.Enmienda.Detalles.EnmiendaMetodologia, 8, 70,new {@class = "Especificaciones"}) %>
这是我拥有的 textAreas 的一个示例。
I have this page which 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"}) %>
That's an example of the textAreas I have.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您没有使用验证插件并且所有文本区域都有“Especaciones”类,您可以在该类上使用过滤器。
如果以下内容的长度大于 0,则至少有一个文本区域具有值。
Assuming you are not using the validate plugin and all the textareas have the "Especificaciones" class, you could use a filter on the class.
If the length of the following is greater than 0, then at least one of the textareas had a value in it.
查看此链接,因为它应该是您要寻找的内容:
jQuery 验证:指示一组中至少需要一个元素
引用上述链接:
首先,我输入 class=组中每个元素的“required_group”。然后,我添加了一个自定义验证方法:
...自定义类规则以利用新方法:
...最后是新方法的自定义消息:
这是使用此方法但对其进行了调整的人的另一个链接:
jquery 只需要验证一组中的一个字段
Check out this link as it should be what your looking for:
jQuery validation: Indicate that at least one element in a group is required
Quoted from the above link:
To start with, I put class="required_group" on each of the elements in the group. Then, I added a custom validation method:
... a custom class rule to take advantage of the new method:
... and finally a custom message for the new method:
Here is another link to someone that used this method but tweaked it:
jquery validation only one field in a group required