开发者

jQuery Validate: Checked *or* Filled?

开发者 https://www.devze.com 2022-12-26 16:10 出处:网络
required( dependency-expression ) They give an example of required: \"#other:checked\" but I want my fi开发者_如何学Pythoneld to be required if the #other field is either :checked or :filled (I don\'

required( dependency-expression )

They give an example of required: "#other:checked" but I want my fi开发者_如何学Pythoneld to be required if the #other field is either :checked or :filled (I don't know whether it will be a checkbox, radio button, or textbox beforehand). How would I do this?


Since it checks length of the jquery element matching this selector, this should work:

required: "#other:checked, #other:filled"

This is the code that actually uses that string:

return !!$(param, element.form).length;

An easier way to think about it: if $(yourString, yourForm).length > 0, it will be a required field.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号