简体   繁体   English

我如何使用jquery验证插件进行条件验证

[英]how do i use the jquery validation plugin to conditional validate

I am using the bassistance jQuery plugin validation. 我正在使用bassistance jQuery插件验证。

I have a drop down list with 2 values. 我有一个带有2个值的下拉列表。

If the first value is selected by the user a valid date field needs to be populated and if the second option is selected then a textbox needs to be filled with some text. 如果用户选择了第一个值,则需要填写有效的日期字段,如果选择了第二个选项,则需要在文本框中填充一些文本。

If nothing is selected then it need to return a validation on this as well 如果未选择任何内容,则还需要对此进行验证

How can I achieve this? 我该如何实现?

thanks 谢谢

Well, if it is a dropdown, you can't really have "nothing" selected. 好吧,如果这是一个下拉列表,则您实际上无法选择“无”。 So, it sounds like in your case, you might want to make three options, the first of which is something like "Choose one", you can then you the jQuery to test for this condition and throw an alert if that value isn't one of the two that trigger an action. 因此,听起来像是在您的情况下,您可能要选择三个选项,第一个选项是“ Choose one”,然后您可以使用jQuery测试此条件并在该值不为零时发出警报触发动作的两个之一。 You can then force them to go back and choose of the two other options. 然后,您可以强迫他们返回并选择其他两个选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM