<body>
<p id="f">我们都是好孩子</p>
<input type="checkbox" name="a" id="a">a
<input type="checkbox" name="b">b
  <script type="text/javascript">
if(document.getElementById("a").checked==true){
alert("hi");
}
  </script>
 </body>为何选中复选框,又没弹出东西呢?

解决方案 »

  1.   

    <body>
    <p id="f">我们都是好孩子</p>
    <input type="checkbox" name="a" id="a" onclick="test();">a
    <input type="checkbox" name="b">b
      <script type="text/javascript">
    function test(){
    if(document.getElementById("a").checked==true){
    alert("hi");
    }
    }
      </script>
     </body>
      

  2.   

    <!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=utf-8" />
    <title>无标题文档</title>
    </head><body>
    <p id="f">我们都是好孩子</p>
    <input type="checkbox" name="a" id="a">a
    <input type="checkbox" name="b">b 
      <script type="text/javascript">
    document.getElementById("a").onclick = function(){
    if(this.checked){
    alert('a')
    }
    };
    </script>
    </body>
    </html>