<html>
<head>
<meta charset="utf-8">
<script src="http://oa.feeyo.com/js/jquery-1.4.2.min.js" type="text/javascript"></script>
</head>
<body>
<div id='xxx'>
<input type="checkbox" value="橘子" id='id2' name="check">橘子1</input>
<input type="checkbox" value="香蕉" id='id3' name="check">香蕉1</input>
<input type="checkbox" value="西瓜" id='id4' name="check">西瓜1</input>
<input type="checkbox" value="芒果" id='id5' name="check">芒果1</input>
<input type="checkbox" value="葡萄" id='id6' name="check">葡萄1</input>
<input type="button" value="获取" id="b1">
</div>
</body>
<script>
//方法1
$("#b1").click(function(){
var data_arr =[]; //定义一个空数组 用于存放数组json
//获取选中的多多选框 #xxx自己改 因为是多个多选框 结果就是一个数组 如果是 单选框或者是输入框 就不是数组
var check_arr = $('#xxx input[type=checkbox]:checked');
alert(check_arr.length); // 弹出看看有几个
//然后循环他
$.each(check_arr,function(){
//想数组里添加一个元素
data_arr.push(
{
id:$(this).attr('id'),
value:$(this).val()
}
);
});
console.log(data_arr);
});
</script>
</html>