Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery中从ul li获取多个检查值_Javascript_Jquery_Css - Fatal编程技术网

Javascript 在jquery中从ul li获取多个检查值

Javascript 在jquery中从ul li获取多个检查值,javascript,jquery,css,Javascript,Jquery,Css,我已经包括了给定的代码 <ul class="checkboxes"> <li class=" "> <label title="" for="option-0"> <input type="checkbox" aria-selected="true" title="" value="All" name="country" id="option-0"><i>All</i> </label

我已经包括了给定的代码

<ul class="checkboxes">
  <li class=" ">
    <label title="" for="option-0">
      <input type="checkbox" aria-selected="true" title="" value="All" name="country" id="option-0"><i>All</i>
    </label>
  </li>
  <li class=" ">
    <label title="" for="option-1">
      <input type="checkbox" title="" value="1" name="country" id="option-1" aria-selected="true"><i>test</i>
    </label>
  </li>
  <li class=" ">
    <label  title="" for="option-2">
      <input type="checkbox" title="" value="2" name="country" id="option-2" aria-selected="true"><i>abcd</i>
    </label>
  </li>
  <li class=" ">
    <label  title="" for="option-3">
      <input type="checkbox" title="" value="3" name="country" id="option-3" aria-selected="true"><i>loreum</i>
    </label>
  </li>
  <li class=" ">
    <label  title="" for="option-4">
      <input type="checkbox" title="" value="4" name="country" id="option-4" aria-selected="true"><i>ipsum</i>
    </label>
  </li>
</ul>
  • 全部的
  • 测验
  • abcd
  • 洛勒姆
  • 乱数假文
我想从列表中获取检查值,例如:如果我已经选择了ipsum loreum并测试了如何通过jquery获取这些文本。请帮帮我。提前感谢

您可以对所有选中的元素使用
.map()
函数从同级i元素返回文本数组:

$('ul input:checked').map(function(){
   return $(this).next('i').text();
}).get();

您可以对所有选中的元素使用
.map()
函数从同级i元素返回文本数组:

$('ul input:checked').map(function(){
   return $(this).next('i').text();
}).get();

给您:

$('input')。更改(函数(){
var-str='';
log($('input:checked').length);
$。每个($('input:checked'),函数(索引,值){
str+=$(值).next('i').text()+',';
});
警报(“您选中:”+str);
});

  • 全部的
  • 测验
  • abcd
  • 洛勒姆
  • 乱数假文
给您:

$('input')。更改(函数(){
var-str='';
log($('input:checked').length);
$。每个($('input:checked'),函数(索引,值){
str+=$(值).next('i').text()+',';
});
警报(“您选中:”+str);
});

  • 全部的
  • 测验
  • abcd
  • 洛勒姆
  • 乱数假文

您将使用jQuery映射获得它

getValues=function(){
var值=$('input[name=country]:checked').map(函数(){
返回$(this.val();
}).get();
警报(数值);
}

  • 全部的
  • 测验
  • abcd
  • 洛勒姆
  • 乱数假文

您将使用jQuery映射获得它

getValues=function(){
var值=$('input[name=country]:checked').map(函数(){
返回$(this.val();
}).get();
警报(数值);
}

  • 全部的
  • 测验
  • abcd
  • 洛勒姆
  • 乱数假文