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

js 把所选中的复选框的值 存到集合中
<!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>无标题文档</title>
<SCRIPT language=JavaScript>
	function hh(){
		var str=document.getElementsByName("1");
		var objarray=str.length;
		var a = new Array();
		for (i=0;i<objarray;i++){
		   if(str[i].checked == true){
		   		a.push(str[i].value);
			}
		}
		for (i=0;i<a.length;i++){
		   alert(a[i]);
		}
	}
</SCRIPT>
</head>

<body>
<input type="checkbox" name="1" onclick="hh();" value="中国1" />
<input type="checkbox" name="1" onclick="hh();" value="中国2" />
<input type="checkbox" name="1" onclick="hh();" value="中国3" />
<input type="checkbox" name="1" onclick="hh();" value="中国4" />

</body>
</html>