日期:2014-05-16 浏览次数:20381 次
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script>
function test(){
$("#chkDiv :checkbox").each(function(){
console.log($(this).is(":checked"));
})
}
</script>
<div id="chkDiv">
<input type=checkbox />
<input type=checkbox />
<input type=checkbox />
<input type=button value="TEST" onclick="test();" />
</div>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>无标题页</title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function(){
var str = "";
var info = getChkInfo("divCheckBoxes");
str = "容器元素内有name的checkbox共有" + info.length +"组\n" ;
for(var i in info)
{
var obj = info[i];
str += "组名:"+obj.name +", 组元素个数:" + obj.count +", 组中元素选中个数:"+ obj.checkedCount +"\n";
}
alert(str);
});
function getChkInfo(id)
{
var result = {}, nameArr=[], groupArr = [];
var $obj = $("#"+id);
$obj.find(":checkbox").each(function(){
var $chk = $(this);
if( this.name != undefined && this.name!=null && this.name!=""