兰斯8迷宫4:javascript关于复选框判断及按钮提交的问题

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/02 16:59:02
<!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>
<script language="javascript">

function bb()
{
if (document.myform.txt.value=="")
{
alert("必须填写姓名");
document.myform.txt.focus();}
}
function cc()
{
if (document.myform.tt.checked==false)
alert("学历必须填写");
else
document.write(<h2>"您的详细信息"</h2><br>"年的姓名是:"+a+<br>"您具有:"+b+"学历");
}
</script>
</head>

<body>
<table align="center">
<tr><td colspan="2">详龙娱乐网页</td></tr>
<td>姓名*</td>
<td><form name="myform"><input type="text" value="" name="txt" onBlur="bb()"></form></td>
<tr><td colspan="2">学历</td></tr>
<tr><td><input name="tt" type="checkbox" value="1">大专
<input name="tt" type="checkbox" value="2">理学学士
<input name="tt" type="checkbox" value="3">理学硕士
</tr>
<tr><td colspan="2"><input type="button" align="middle" value="显示" name="anniu" onClick="cc()"></td></tr>
</table>
</body>
</html>

//程序有错误,文本框函数无错误。
您的答案不正确。还是有错。

我帮您改一下吧,楼上的对了一点,您本身程序少上myform。

<!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>
<script language="javascript">
function bb()
{
if (document.myform.txt.value=="")
{
alert("必须填写姓名");
document.myform.txt.focus();
}
}

function cc(){
var o= document.myform.elements["tt"]
isOk=false
for(i=0;i<o.length;i++)
if(o[i].checked) isOk=true
if(isOk)
{
document.write("<h2>您的详细信息</h2><br>你的姓名是:"+document.myform.txt.value+"<br>您具有:"+document.all.tags("input")[i].value+"学历");
}
else
{
alert("学历必须填写")
return false
}
}
</script>
</head>

<body>
<table align="center">
<form method="POST" name="myform">
<tr><td colspan="2">详龙娱乐网页</td></tr>
<td>姓名*</td>
<td><input type="text" value="" name="txt" onBlur="return bb()"></td>
<tr><td colspan="2">学历</td></tr>
<tr>
<td colspan="2">
<input name="tt" type="checkbox" value="大专">大专
<input name="tt" type="checkbox" value="理学学士">理学学士
<input name="tt" type="checkbox" value="理学硕士">理学硕士
</td>
</tr>
<tr>
<td colspan="2"><input type="button" align="middle" value="显示" name="anniu" onclick="return cc()"></td>
</tr>
</form>
</table>
</body>
</html>

document.write(<h2>"您的详细信息"</h2><br>"年的姓名是:"+a+<br>"您具有:"+b+"学历");
改为:
document.write("<h2>您的详细信息</h2><br>你的姓名是:"+a+"<br>您具有:"+b+"学历");