教程集 www.jiaochengji.com
教程集 >  脚本编程  >  javascript  >  正文 js获取CheckBox多选框值的代码

js获取CheckBox多选框值的代码

发布时间:2014-10-16   编辑:jiaochengji.com
为大家介绍一个Javascript获取checkbox多选框中值的代码,以前接触到的大多是asp或php直接实现的,用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>js获取CheckBox多选框值_www.jbxue.com</title>
<script language="javascript">
/**
 * checkbox多选框值
 * www.jbxue.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>

您可能感兴趣的文章:
js判断复选框checkbox是否选中并取出值
JQuery对checkbox操作 (循环获取)
php获取checkbox值
jquerymobile checkbox及时刷新才能获取其准确值
js获取CheckBox多选框值的代码
jquery如何获取复选框的值
jquery获取checkbox的操作总结
php实例:取得checkbox复选框中的多选值
jquery获取复选框被选中的值
jquery checkbox复选框是否选中的检测代码

关键词: checkbox  复选框   
[关闭]
~ ~