基于条件的jQuery验证maxlength参数 [英] jQuery Validation maxlength parameter based on conditional

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

问题描述

如何使用jQuery Validation根据条件更改文本框的最大长度.

How to change the maxlength of a textbox using jQuery Validation based on a condition.

代码

 SSN: { required: true, minlength: 9, maxlength: 9 }

如何根据if-else条件更改最大长度?

How do I change the maxlength based on an if-else condition?

推荐答案

三元表达式是否是您想要的?

Would a ternary expression be what you want ?

SSN: { required: true, minlength: 9, maxlength: ((condition)?true:false) }

示例:

SSN: { required: true, minlength: 9, maxlength: ((my_var=="short")?13:17) }

如果满足条件,将打印13,否则打印17

Would print 13 if the condition is met, otherwise 17

校正最大长度,使其大于最小长度.

Correcting the max lenght so it is bigger than the min lenght.

这篇关于基于条件的jQuery验证maxlength参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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