87,902
社区成员
发帖
与我相关
我的任务
分享
<div id="div1">
<input type="checkbox" name="fruit" value="Banana" />Banana
<p>
</p>
<input type="checkbox" name="fruit" value="Apple" checked="checked" />Apple
<p>
</p>
<input type="checkbox" name="fruit" value="Orange" />Orange
<p>
</p>
<input type="checkbox" name="fruit" value="Pear" />Pear
<p>
</p>
<input type="checkbox" name="fruit" value="Peach" />Peach
<p>
</p>
<input type="hidden" name="hid" value="" />
<input type="button" value="提交" onclick="a();" />
<input type="reset" value="重置" />
</div>
function a()
{
var hidstr="";
var cbs=document.getElementById('div1').getElementsByTagName('input');
for(i=0;i <cbs.length;i++)
{
if(cbs[i].type!='checkbox') continue;
if(!cbs[i].checked) continue;
hidstr+=cbs[i].value+",";
}
if(hidstr.length>0)
hidstr=hidstr.substring(0,hidstr.lastIndexOf(','));
alert(hidstr);
}