【问题标题】:Atleast one drop down value must be selected from multiple drop downs using jquery validation plugin必须使用 jquery 验证插件从多个下拉列表中选择至少一个下拉值
【发布时间】:2017-03-29 04:33:44
【问题描述】:

我在一个表格中有多个下拉菜单,并且应该根据业务规则从表格中至少选择一个下拉菜单。我正在使用 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>

enter image description here

【问题讨论】:

  • 问题是什么?

标签: javascript jquery html jsf


【解决方案1】:

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

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

【讨论】:

  • 嗨 efilho " $('#hoursShiftsTable select option[selected=selected][value!=" "]') " 它没有给我任何选择的选项。
  • 哦,你想要 SELECTED OPTIONS 值???如果有任何选定的选项,我以为你想要验证,抱歉。在这种情况下:$('#hoursShiftsTable select option[selected=selected][value!=" "]').each(function(i,j){alert(j.value);}) 这将遍历选定的值(由j.value 表示)
  • 如果您看到我上面的代码,我在下拉菜单中的第一个选项是 "select" 。对于我的验证,我想将下拉选项从选择更改为空值。我该怎么做?
  • 看看这个帖子stackoverflow.com/questions/10547622/…,我试过了,它奏效了。在您的情况下:$('#hoursShiftsTable select').val(' ').trigger('change');。希望它有所帮助,最好的问候。
  • 这会给我下一行列的值吗!!$("#" + elemId + 'td:nth-child(1) option:selected' ).text()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-07-06
  • 1970-01-01
相关资源
最近更新 更多