jquery取得多选checkbox选中的值

来源:互联网 发布:软件采购招标评分标准 编辑:程序博客网 时间:2024/05/22 07:55

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="http://libs.baidu.com/jquery/1.8.3/jquery.min.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();" value="000"/>  </div> </body></html>


0 0