代码如下:
<!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> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>判断checkbox是否选中-www.jb200.com</title> <script language="javascript"> function test(obj) { //alert(obj.value); //alert(obj.name); var cname = "BUKRS"; var ename = "PUR_ORG"; for(i=0;i<document.all(ename).length;i++) { if(document.all(ename)[i].checked ==false && document.all(ename)[i].value==obj.value) document.all(ename)[i].checked = true; else if(document.all(ename)[i].checked ==true && document.all(ename)[i].value==obj.value) document.all(ename)[i].checked = false; } } </script> </head> <body> <TABLE BORDER=1 WIDTH="100%" style="margin-top:20px"> <tr> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1000" onclick="test(this);">台北</TD> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1600" onclick="test(this);">北京</TD> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1605" onclick="test(this);">武漢</TD> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1603" onclick="test(this);">大連</TD> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1602" onclick="test(this);">上海</TD> <TD CLASS="Default"><INPUT NAME="BUKRS" TYPE="CHECKBOX" CLASS="Default" VALUE="1604" onclick="test(this);">珠海</TD> </TR> </table> <TABLE BORDER=1 WIDTH="100%" style="margin-top:20px"> <tr> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1000">Taibei</TD> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1600">Beijing</TD> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1605">Wuhan</TD> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1603">Dalian</TD> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1602">Shanghai</TD> <TD CLASS="Default"><INPUT NAME="PUR_ORG" TYPE="CHECKBOX" CLASS="Default" VALUE="1604">Zhuhai</TD> </TR> </table> </body> </html>