<%@ 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>
这样子为何不执行呀
<!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>
这样子为何不执行呀
document.form1.checkbox[1].checked 改为document.form1.checkbox1.checked;
document.form1.checkbox[1].checked 改为document.form1.checkbox1.checked;
改成这样子,也没有反应呢,在ASP中这样子就可以,但在JSP中怎么也不成功呀
<!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>
<!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>
第一种是加了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>
注意事件是onclick,不是onchange