jQuery 验证:选中*或*已填充?
他们给出了 required: "#other:checked"
的示例,但我希望如果 #other
字段是 :checked 或
:filled
(我事先不知道它是复选框、单选按钮还是文本框)。我该怎么做?
required( dependency-expression )
They give an example of required: "#other:checked"
but I want my field 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它检查与此选择器匹配的 jquery 元素的长度,因此应该可以工作:
这是实际使用该字符串的代码:
一种更简单的思考方法: if
$(yourString, yourForm).length > 0
,这将是必填字段。Since it checks length of the jquery element matching this selector, this should work:
This is the code that actually uses that string:
An easier way to think about it: if
$(yourString, yourForm).length > 0
, it will be a required field.