作品第一课----获取批量checkbox选中的值

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
</head>
<body>
  <div>
    <label>
      <input type="checkbox" value="1">
    </label>
    <label>
      <input type="checkbox" value="2">
    </label>
    <label>
      <input type="checkbox" value="3">
    </label>
    <label>
      <input type="checkbox" value="4">
    </label>
    <label>
      <input type="checkbox" value="5">
    </label>
    <label>
      <input type="checkbox" value="6">
    </label>
    <label>
      <input type="checkbox" value="7">
    </label>
    <label>
      <input type="checkbox" value="8">
    </label>
    <label>
      <input type="checkbox" value="9">
    </label>
    <label>
      <input type="checkbox" value="10">
    </label>

  </div>
  <input class="ceshi" type="button" value="确定">
  
<script>
  $(".ceshi").on("click", function(){
    var num = $("div label").length;
    var zhi = []
    for(var i = 0; i < num; i++) {
      if ($("div label").eq(i).find("input").is(":checked")) {
        var chk = $("div label").eq(i).find("input").val();
        zhi.push(chk);
      };
    } 
    alert(zhi);
  })
</script>
</body>
</html>
原文地址:https://www.cnblogs.com/samtrybest/p/5071452.html