jQuery 验证:选中*或*已填充?

发布于 2024-08-28 05:56:06 字数 336 浏览 3 评论 0原文

必需(依赖表达式)

他们给出了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑色毁心梦 2024-09-04 05:56:06

由于它检查与此选择器匹配的 jquery 元素的长度,因此应该可以工作:

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

这是实际使用该字符串的代码:

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

一种更简单的思考方法: if $(yourString, yourForm).length > 0,这将是必填字段。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文