通达OA,js控制复选框checkbox,获取复选框的值

<!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>
<style type="text/css">
.div_c{
	font-size:13px;
	text-align:center;
	background-color:#0FF;
	border:#F00 2px solid;
	width:50%;
	height:100px;
	margin:auto;
	}
</style>
</head>
<script type="text/javascript">

function jiance(){
var btn = document.getElementById("btn");
var test = document.getElementsByName("test");
var a=0;
btn.onclick = function(){
for(var i=1; i<=test.length; i+=1){
if(test[i-1].checked){
alert(test[i-1].value);
alert("当前有选中!");
a=1;
//return;
}
}
};
if(a==0){
	alert("一个也没有选中!");
	}
	}
function check(){
	var test1=document.getElementById("test1");
	var test1_value=test1.value;
	if(test1.checked){
		alert(test1_value+"是被选中的了!");
		document.getElementById("div1").style.display="";
		} else {
			alert(test1_value+"没有被选中的了!");
			document.getElementById("div1").style.display="none";
			}
	var test2=document.getElementById("test2");
	var test2_value=test1.value;
	if(test2.checked){
		alert(test2_value+"是被选中的了!");
		document.getElementById("div2").style.display="";
		} else {
			alert(test2_value+"没有被选中的了!");
			document.getElementById("div2").style.display="none";
			}
	
	}	
</script>
<body>
<div style="text-align:center; margin-top:20px; font-size:13px;">
<input type="checkbox" name="test"  id="test1" οnclick="check();" value="testa"/>飞机
<input type="checkbox" name="test"  id="test2" οnclick="check();" value="testb"/>火箭
<input type="checkbox" name="test"  id="test3" οnclick="check();" value="testc"/>大炮
<input type="checkbox" name="test"  id="test4" οnclick="check();" value="testd"/>坦克
<input type="checkbox" name="test"  id="test5" οnclick="check();" value="teste"/>导弹
<input type="button" value="检测" id="btn"  οnclick="jiance();"/>
</div>
<hr>

<div id="div1" class="div_c" style="display:none">第一段内容<br>1111111111111111111</div>
<div id="div2" class="div_c" style="display:none">第二段内容<br>2222222222222222222</div>
</body>
</html>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

hai7425

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值