jquery取出checkbox多选的值(带全选功能)

时间:2021-05-01 00:20:48

<!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 submit() {
  var str="";
  $("input:checkbox:not(#checkAll):checked").each(function(){
    str += $(this).val()+","
  })
  alert(str);
}
</script>
<body>
  <div>
    <input type="checkbox" name="checkAll" value="0" id="checkAll">全选
    <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="submit();" value="submit"/>
  </div>
</body>
</html>