码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-12-23 22:33:13      阅读:253      评论:0      收藏:0      [点我收藏+]

标签:

<!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>

 

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

标签:

原文地址:http://www.cnblogs.com/samtrybest/p/5071452.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!