Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/384.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获取一组复选框值_Javascript_Jquery - Fatal编程技术网

Javascript 使用jquery获取一组复选框值

Javascript 使用jquery获取一组复选框值,javascript,jquery,Javascript,Jquery,在一组复选框中,如php中生成的 <?php foreach($estados as $estado){ $html = '<div class="checkbox chk_estado">'; $html .= '<label><input type="checkbox" class="estate_check" value="" chk_id="'.$estado->id_estat.'" />

在一组复选框中,如php中生成的

<?php
     foreach($estados as $estado){
          $html = '<div class="checkbox chk_estado">';
          $html .= '<label><input type="checkbox" class="estate_check" value="" chk_id="'.$estado->id_estat.'" />'.$estado->estat.'</label>';
          $html .="</div>";

          echo $html;
      }
 ?>

如果要在HTML元素中存储某些内容,请使用
data-*
属性。在这种情况下,请使用
数据检查id=“…”

您将得到这样一个数组

Array [ "1", "2" ]

检查身份证???您正在使用chk_idI投票结束此问题,因为这是一个打字错误。您是否知道
.attr()
获取匹配元素集中第一个元素的属性值。请尝试以下操作
<div class="checkbox chk_estado">
  <label>
    <input type="checkbox" class="estate_check" value="A" data-check-id="1">
    Something
  </label>
</div>
<div class="checkbox chk_estado">
  <label>
    <input type="checkbox" class="estate_check" value="B" data-check-id="2">
    Something
  </label>
</div>
<div class="checkbox chk_estado">
  <label>
    <input type="checkbox" class="estate_check" value="C" data-check-id="3">
    Something
  </label>
</div>
const getAllChecked = () =>
  Array.from(
    document.getElementsByClassName('estate_check')
  )
    .filter(x => x.checked)
    .map(x => x.dataset.checkId);
Array [ "1", "2" ]