繁体   English   中英

从jQuery中的multiselect复选框中获取检查值

[英]fetch checked value from multiselect checkbox in jquery

我给了html

<ul class="ui-multiselect-checkboxes ui-helper-reset" style="height: 175px;">
  <li class=" ">
    <label class="ui-corner-all" title="" for="ui-multiselect-opps-option-0">
      <input type="checkbox" title="" value="All" name="opps" id="ui-multiselect-opps-option-0">
      <i>All</i>
    </label>
  </li>
  <li class=" ">
    <label class="ui-corner-all" title="" for="ui-multiselect-opps-option-1">
      <input type="checkbox" title="" value="1" name="opps" id="ui-multiselect-opps-option-1">
      <i>John</i>
    </label>
  </li>
  <li class=" ">
    <label class="ui-corner-all" title="" for="ui-multiselect-opps-option-2">
      <input type="checkbox" aria-selected="true" checked="checked"  title="" value="3" name="opps" id="ui-multiselect-opps-option-2">
      <i>Tim</i>
    </label>
  </li>
  <li class=" ">
    <label class="ui-corner-all" title="" for="ui-multiselect-opps-option-3">
      <input type="checkbox" aria-selected="true" checked="checked" title="" value="2" name="opps" id="ui-multiselect-opps-option-3">
      <i>Tom</i>
    </label>
  </li>
</ul>

并包含给定的jQuery代码

$("input[id^='ui-multiselect-opps-option']").attr('checked').val();

但它不提取检查值,请指导我如何通过jquery提取多选检查值。

在jquery中使用.map() 它用于将数组或对象中的所有项目转换为新的项目数组。

var res = $("input[id^='ui-multiselect-opps-option']:checked").map(function() {
  return $(this).val();
}).get();

 console.log(res);

小提琴

暂无
暂无

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

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