<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body>
<script language="JavaScript" type="text/JavaScript">
 function get1()
 {
  if (document.form1.checkbox[2].checked==true)
   {
     document.form1.checkbox[1].checked = true;
   }
 }
</script>
<input type="checkbox" name="checkbox2" value="checkbox" onChange="get1()">
<input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox">
</body>
</html>
这样子为何不执行呀

解决方案 »

  1.   

    document.form1.checkbox[2].checked 改为document.form1.checkbox2.checked;
    document.form1.checkbox[1].checked 改为document.form1.checkbox1.checked;
      

  2.   

    document.form1.checkbox[2].checked 改为document.form1.checkbox2.checked;
    document.form1.checkbox[1].checked 改为document.form1.checkbox1.checked;
    改成这样子,也没有反应呢,在ASP中这样子就可以,但在JSP中怎么也不成功呀
      

  3.   

    你的页面中根本就没有<form name="form1">,执行document.form1...当然就不成功啦
      

  4.   

    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <script language="JavaScript" type="text/JavaScript">
     function get1()
     {
      if (document.form1.checkbox[2].checked==true)
       {
         document.form1.checkbox[1].checked = true;
       }
     }
    </script>
    <form name="form1" method="post">
    <input type="checkbox" name="checkbox2" value="checkbox" onChange="get1()">
    <input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox">
    </form>
    </body>
    </html>
      

  5.   

    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <script language="JavaScript" type="text/JavaScript">
     function get1()
     {
      if (document.form1.checkbox2.checked==true)
       {
         document.form1.checkbox1checked = true;
       }
     }
    </script>
    <form name="form1" method="post">
    <input type="checkbox" name="checkbox2" value="checkbox" onChange="get1()">
    <input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox">
    </form>
    </body>
    </html>
      

  6.   

    为什么要用onChange?用onclick好了
      

  7.   

    不好意思,刚才太急,没检查你的代码,不知道你为什么不加form下面这样写都可以,
    第一种是加了from的:
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <script language="JavaScript" type="text/JavaScript">
     function get1()
     {
      if (document.form1.checkbox2.checked==true)
       {
         document.form1.checkbox1.checked = true;
       }
     }
    </script>
    <form name="form1" method="post">
    <input type="checkbox" name="checkbox2" value="checkbox" onClick="get1()">
    <input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox">
    </form>
    </body>
    </html>
    第二种是没加form的:
    <%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>无标题文档</title>
    </head><body>
    <script language="JavaScript" type="text/JavaScript">
     function get1()
     {
     alert("sdfasfd");
      if (document.all.checkbox2.checked==true)
       {
         document.all.checkbox1.checked = true;
       }
     }
    </script>
    <form name="form1" method="post">
    <input name="checkbox2" type="checkbox" id="checkbox2" onClick="get1()" value="checkbox">
    <input name="checkbox1" type="checkbox" id="checkbox1" value="checkbox">
    </form>
    </body>
    </html>
      

  8.   

    楼上的正解~~
    注意事件是onclick,不是onchange