jQuery 验证 - 需要回答所有问题或选择退出调查

发布于 2024-07-14 23:30:13 字数 649 浏览 4 评论 0原文

我们有一份注册表,要求提供人口统计信息,还可以选择不提供任何信息。 但是,为了保持我们的数字正确相加,如果您选择任何人口统计数据,我们希望要求您输入所有信息。 表格渲染:

  • 性别
    • ( ) 男
    • ( ) 女
  • 残疾?
    • ( ) 是
    • ( ) 否
  • 种族
    • ( ) A
    • ( ) B
    • ( ) C
  • ( ) 我不想提供人口统计信息

我们希望允许选择“我不希望...”和所有选项,例如“男性/是/A” ,但不是部分答案,例如“女性/C”。

我们如何构建 .validate() 规则和选项来实现这一目标? 理想情况下,如果您的回复不充分,我们将显示/隐藏单个标签。

其他信息:

We have a registration form that asks for demographic information with the additional option to not provide any information. However, to keep our numbers adding up properly, we want to require you to enter all information if you select any demographics. A rendering of the form:

  • Gender
    • ( ) Male
    • ( ) Female
  • Disabilities?
    • ( ) Yes
    • ( ) No
  • Race
    • ( ) A
    • ( ) B
    • ( ) C
  • ( ) I do not wish to provide demographic information

We want to allow selection of "I do not wish..." and all options, e.g. "Male/Yes/A", but not partial answers, e.g. "Female/C".

How can we structure the .validate() rules and options to achieve this goal? Ideally, we would have a single label show/hide if your response is not sufficient.

Additional information:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

维持三分热 2024-07-21 23:30:13

I'm assuming that you are using the jQuery validation plugin. If so, what you want is a custom require rule with a dependency check that allows you to make the inputs required iff the user does not choose to opt out. You might want to have a click handler on the opt-out that clears the other fields so that you don't have to check for partial entries when the user does choose to opt out.

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