<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><body>
<input name="a23" type="checkbox" id="a3" onClick="javascript:gb()" checked="checked">
<div id="ab"></div>
<script language="javascript">
<!--function gb()
 {
 ab.innerHTML="<input id=ab name=sdd type=hidden value=s>"
    
 } 
--></script>
</body>如上面,我想在点CHECKBOX的时候,当CHECKED被选中的时候 DIV的位置变成一个隐藏的域,可是发现实现不了,我是不是弄错了,怎么做才能实现这个功能
</html>

解决方案 »

  1.   

    document.getElementById(“a3").style.display = "none";
      

  2.   

    <input name="a23" type="checkbox" id="a3" onClick="gb('ab')" checked="checked" />
    <div id="ab" style="background:#F00;height:50px;display:none"></div>
    <script language="javascript">
    function gb(id){
       var id = document.getElementById(id);
       if( id.style.display == "block" ){
           id.style.display = "none";
       }else{
       id.style.display = "block";
       }
    }
    </script>
      

  3.   

    就楼上的代码,把 if(id.style.display=='block') 改为 if(id.checked) 可能会好些
      

  4.   

    这样就可以了<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 gb(obj){
    var div = document.getElementById("ab");
    if(obj.checked){
    div.style.display = "";
    }else{
    div.style.display = "none";
    }
    }
    </script>
    </head><body>
    <input name="a23" type="checkbox" id="a3" onClick="gb(this)" checked="checked" />
    <div id="ab">aaaaaaaaaaaaaaaaaa</div>
    </body>
      

  5.   

    上面实现反效果了,汗
    <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 gb(obj){
    var div = document.getElementById("ab");
    if(obj.checked){
    div.style.display = "none";
    }else{
    div.style.display = "";
    }
    }
    </script>
    </head><body>
    <input name="a23" type="checkbox" id="a3" onClick="gb(this)" checked="checked" />
    <div id="ab" style="display:none">aaaaaaaaaaaaaaaaaa</div>
    </body>