代码如下:
<!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>js获取checkbox多选框值_www.jb200.com</title> <script language="javascript"> /** * checkbox多选框值 * www.jb200.com */ function test() { var value=""; //document.getElementsByName("value1").value; for(i=0;i<4;i++) { if(document.getElementsByName("Status")[i].checked==true) { if(value==""){ value=value+document.getElementsByName("Status")[i].value; } else{ value=value+","+document.getElementsByName("Status")[i].value; } } } alert(value); document.all.value1.value = value; } </script> </head> <body> <input name="Status" type="checkbox" value="1" onclick="test()"/> <input name="Status" type="checkbox" value="2" onclick="test()"/> <input name="Status" type="checkbox" value="3" onclick="test()"/> <input name="Status" type="checkbox" value="4" onclick="test()"/> <input type="text" name="value1" value="" size="50"/> </body> </html>