zoukankan      html  css  js  c++  java
  • 作品第一课----获取批量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
Copyright © 2011-2022 走看看