Javascript 必须使用jquery验证插件从多个下拉列表中选择至少一个下拉列表值

Javascript 必须使用jquery验证插件从多个下拉列表中选择至少一个下拉列表值,javascript,jquery,html,jsf,Javascript,Jquery,Html,Jsf,我在一个表中有多个下拉列表,根据业务规则,应该从表中至少选择一个下拉列表。我正在使用jquery验证插件和jsf。 提前谢谢!! //jsf代码 div id="hoursShiftsModal"> <table id="hoursShiftsTable"> <col width="5%"/> <col width="5%"/> <col width="5%"/>

我在一个表中有多个下拉列表,根据业务规则,应该从表中至少选择一个下拉列表。我正在使用jquery验证插件和jsf。 提前谢谢!! //jsf代码

div id="hoursShiftsModal">
   <table id="hoursShiftsTable">
          <col width="5%"/>
          <col width="5%"/>
           <col width="5%"/>
           <col width="5%"/>
        <thead>
        <tr>
              <th>Hours</th>
             <th>Jan</th>
             <th>Feb</th>
     </tr>
    </thead>
    <tbody>
    <tr>
     <td><label>Starting</label></td>
    <td>
    <h:selectOneMenu id="janStartTime" class="required timeZone      workShiftsGroup" >
    <f:selectItem itemValue="Select" itemLabel="Select" ></f:selectItem> 
    <f:selectItems value=" "></f:selectItems>                                                                                                                                                               
   </h:selectOneMenu>
   </td>
  <td>
   <h:selectOneMenu id="febStartTime" class="required timeZone workShiftsGroup "  >
   <f:selectItem itemValue="Select" itemLabel="Select" ></f:selectItem> 
   <f:selectItems ></f:selectItems>                                                                                                                                                               
 </h:selectOneMenu>
 </td>
</tbody>
</table>

这可能有效:它将搜索嵌套在表中的“选定”选项

function valid() {
    return $('#hoursShiftsTable select option[selected=selected][value!=" "]').size() > 0;
}

问题是什么?嗨,efilho$'hoursShiftsTable选择选项[selected=selected][value!=]”它没有给我任何选择的选项。哦,你想要选择的选项值吗???我以为你想要验证是否有任何选择,抱歉。在这种情况下:$'hoursShiftsTable选择选项[selected=selected][value!=]'。每个函数i,j{alertj.value;}这将遍历由j.value表示的选定值。如果您看到我上面的代码,我在下拉列表中的第一个选项是select。对于我的验证,我想将下拉选项从select更改为空值。我怎么能做到呢?看看这篇文章,我试过了,它成功了。在您的情况下:$'hoursShiftsTable select'.val'。触发'change';。希望有帮助,祝你好运。这会给我下一行的列的值吗!!$+elemId+“td:nth-child1选项:已选定”。文本