日期:2014-05-16  浏览次数:20356 次

[高手快来]关于JavaScript中增删Checkbox组的一项或几项~~
http://www2.freep.cn/Photo.php?url=photo36/0705291537017522.bmp

如图,两组checkbox,然后对它他们进行相互增删....最后提交到服务器...高手快来~~~

------解决方案--------------------
<TABLE border=1>
<TR>
<TD id=chk1>
<input type= "checkbox " value= "a "> a
<input type= "checkbox " value= "b "> b
<input type= "checkbox " value= "c "> c
<input type= "checkbox " value= "d "> d

</TD>
<TD>
<input type= "button " value= "> " onclick= "chk2chk( 'chk1 ') ">
<input type= "button " value= " < " onclick= "chk2chk( 'chk2 ') ">
</TD>
<TD id=chk2>
<input type= "checkbox " value= "e "> e


</TD>
</TR>
</TABLE>

<SCRIPT LANGUAGE= "JavaScript " charset= "GBK ">
<!--

function chk2chk(s)
{
var str = (s == "chk1 ") ? "chk2 " : "chk1 ";
var FObj = document.getElementById(s);
var TObj = document.getElementById(str);

for (var i= (FObj.childNodes.length -1) ;i> =0;i--)
{
if (FObj.childNodes[i].tagName == "INPUT " && FObj.childNodes[i].type == "checkbox ")
{
if (FObj.childNodes[i].checked == true)
{//yidong
TObj.appendChild(FObj.childNodes[i]);
FObj.removeChild(FObj.childNodes[i]);
}
else
{//donothing
}
}
}
}