<form name="frm">
<input type="checkbox" name="a" value="冰箱" οnclick="checkItem();">冰箱
<input type="checkbox" name="a" value="电脑" οnclick="checkItem();">电脑
<input type="checkbox" name="a" value="洗衣机" οnclick="checkItem();">洗衣机
<input type="hidden" name="b">
</form>
<script>
function checkItem(){
var chkbox=document.getElementsByName("a");
var v="";
for(var i=0;i<chkbox.length;i++){
if(chkbox[i].checked) v+=","+chkbox[i].value;
}
document.frm.b.value=v.replace(/^,{1}/,"");
}
</script>
这样就得到一个字符串传入到后台用spilt函数进行分割得到一个字符串数组。