简体   繁体   English

jQuery验证插件-选择框问题

[英]Jquery Validation Plugin - Select Box Problems

I have 9 select boxes on my page containing lots of subcategories for businesses. 我的页面上有9个选择框,其中包含许多企业子类别。 I require the user to select an option from only 1 of the 9 selects. 我要求用户仅从9个选择中选择1个。 To make the user experience better I hide all of the select boxes with CSS and generate a dynamic select box of categories. 为了使用户体验更好,我用CSS隐藏了所有选择框,并生成了一个动态的类别选择框。 When a category is selected from the generated dropdown, the subcategories select box which is hidden by CSS is displayed. 从生成的下拉列表中选择一个类别时,将显示被CSS隐藏的子类别选择框。

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 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. 如果您选择任何其他类别并将子类别留空,我会收到一条错误消息,该消息仍附加在第一项上,但不能将其设置为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. 请帮忙。

(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. Clawg可能有与我相同的问题。 My validation was only running for the first styled selectbox on the page. 我的验证仅针对页面上第一个样式化的选择框运行。

To solve this, add a name attribute to your selectbox. 要解决此问题,请将名称属性添加到您的选择框。 ie

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM