如何用checkbox的值来控制span中内容的显示?

来源:百度知道 编辑:UC知道 时间:2024/05/26 18:31:46
<!--我希望能做成值为1或2的cbx被选中就显示span1或2中的内容,取消选中就隐藏span1或2中的内容-->
<script language=javascript>
function check(){
if(cbx.checked==true)||(cbx.value==1){
shows.style.display="";
}else{
shows.style.display="none";
}
if(cbx.checked==true)||(cbx.value==2){
shows2.style.display="";
}else{
shows2.style.display="none";
}
}
</script>
<html>
<body>
<input type=checkbox id="cbx" onClick="check()" value=1><span id="show1" style="display:none"><input type="text" id="sdhow">1</span>
<input type=checkbox id="cbx" onClick="check()" value=2><span id="show2" style="display:none"><input type="text" id="sdhow" >2</span>
</body>
</html>

<script language=javascript>
function check(){
var cbx = document.getElementsByName("cbx");
for(var i=0; i<cbx.length; i++){
if(cbx[i].checked==true){
eval("show"+cbx[i].value).style.display="";
}else{
eval("show"+cbx[i].value).style.display="none";
}
}
}
</script>
<html>
<body>
<input type=checkbox id="cbx" name="cbx" onClick="check()" value=1>
<span id="show1" style="display:none">1</span>
<input type=checkbox id="cbx" name="cbx" onClick="check()" value=2>
<span id="show2" style="display:none">2</span>
</body>
</html>