Jquery 验证插件 - 选择框问题

发布于 2024-09-07 18:00:29 字数 612 浏览 2 评论 0原文

我的页面上有 9 个选择框,其中包含许多企业子类别。我要求用户仅从 9 个选项中选择一个选项。为了让用户体验更好,我用 CSS 隐藏了所有选择框,并生成了一个动态的类别选择框。当从生成的下拉列表中选择一个类别时,会显示 CSS 隐藏的子类别选择框。

我的问题是,当我提交表单时,验证似乎不起作用。在使用 firebug 进行进一步检查时,看起来验证确实会触发,但仅限于第一个隐藏的选择框(吃和喝)。如果您查看示例页面,我已将所有内容放在一起,就像我希望的饮食类别一样:

http://www.clawg.co.uk/jstest/errortest.html

  • 无类别提交表单显示错误消息
  • 无子类别提交表单显示错误消息
  • 将类别或子类别更改为空白显示错误消息

如果您选择任何其他类别并将子类别留空我收到一条错误消息,该消息仍然附加到第一个项目,但不能被视为其设置为显示:无。奇怪的是,一旦您单击子类别选择框,错误消息就会将其自身附加到正确的项目中,但我确实需要它才能提交。

这真的让我抓狂。请帮忙。

I have 9 select boxes on my page containing lots of subcategories for businesses. I require the user to select an option from only 1 of the 9 selects. To make the user experience better I hide all of the select boxes with CSS and generate a dynamic select box of categories. When a category is selected from the generated dropdown, the subcategories select box which is hidden by CSS is displayed.

My problem is when I submit the form the validation does not appear to work. On further inspection with firebug it looks like the validation does fire, but only for the first hidden select box (eating and drinking). If you look at an example page I have put together everything works as I would hope for the category eating and drinking:

http://www.clawg.co.uk/jstest/errortest.html

  • No category submit form show error message
  • No subcategory submit form show error message
  • Change category or subcategory to blank show error message

If you select any another category and leave the subcategory blank I get an error message which is still attached to first item but cant be seen as its set to display:none. Strangely the error message does append itself to the correct item once you click on the subcategory select box, however I really need it to work on submit.

This one is really driving me nuts. Please help.

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

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

发布评论

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

评论(1

注定孤独终老 2024-09-14 18:00:29

(对于最终到达这里的其他人)我确实意识到这篇文章已经存在一年多了。

Clawg 可能也有和我一样的问题。我的验证仅针对页面上的第一个样式选择框运行。

要解决此问题,请向选择框添加名称属性。
IE

<select name="mySelect" id="my-select-box" class="required">

(for anyone else that ends up here) I do realize this post is over a year old.

Clawg might have the same issue I had. My validation was only running for the first styled selectbox on the page.

To solve this, add a name attribute to your selectbox.
i.e.

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