<!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>
通达OA,js控制复选框checkbox,获取复选框的值
最新推荐文章于 2023-10-19 17:50:03 发布