一段javascript的checkbox 应用 转
转自百度知道
"
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>无标题文档</title> </head> <body> a <input type=checkbox value="t" name="t" > b <input type=checkbox value="x" name="x" /> c <input type=checkbox value="x" name="x" /> d <input type=checkbox value="x" name="x" /> <input type="button" value="确定" name="b" onClick="onClick()"> <INPUT type=reset value=重做 name="Reset"> <br> <input name="yourResult" type="text" id="yourResult" size="50"> <script language="JavaScript" type="text/javascript"> function onClick() { var ChkboxValue = ""; var chks = document.getElementsByTagName("INPUT"); for(var i=0; i<chks.length; i++) { if(chks[i].type=="checkbox" && chks[i].checked ) { if ( ChkboxValue == "" ) ChkboxValue = chks[i].value; else ChkboxValue += ","+chks[i].value; } } if (ChkboxValue == "") ChkboxValue = "你没有选择!"; else ChkboxValue = "你选择的结果是:"+ChkboxValue; document.getElementById("yourResult").value = ChkboxValue; } </script> </body> </html>
"