zoukankan      html  css  js  c++  java
  • jquery取checkbox选中的值

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
     </head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
    
            function go() {
                var str="";
                $("input[name='checkbox']:checkbox").each(function(){ 
                    if($(this).attr("checked")){
                        str += $(this).val()+","
                    }
                })
                //alert(str);
                str.split(",");
                alert(str[0]);
            }
        </script>
     <body>
      <div>
        <input type="text" id="content" value="111"/>
        <input type="checkbox" name="checkbox" value="1"/>
        <input type="checkbox" name="checkbox" value="2"/>
        <input type="checkbox" name="checkbox" value="3"/>
        <input type="checkbox" name="checkbox" value="4"/>
        <input type="checkbox" name="checkbox" value="5"/>
        <input type="button" id="test" onclick="go();"/>
      </div>
     </body>
    </html>

    Js 与 Jquery 最重要的是 找不到相关的值与属性的时候! 记的加 id , class!

  • 相关阅读:
    NYOJ 23 取石子(一)
    XYNUOJ 2026 素数环
    XYNUOJ 1756 魔法工会
    XYNUOJ 1784 胜利大逃亡
    NYOJ 18 The Triangle
    NYOJ 737 合并石子
    XYNUOJ 问题 B: 敌兵布阵
    NYOJ 1063 生活的烦恼
    XYNUOJ 1774 最少拦截系统
    XYNUOJ 1248 排队打水问题
  • 原文地址:https://www.cnblogs.com/wicub/p/3372077.html
Copyright © 2011-2022 走看看