就一个简单的注册,在提交表单前用javascript验证下,如果文本框或性别没有选择就弹出提示,不提交表单~汗,我错哪了~5555
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function check()
{
var u=document.getElementById("txtU");
var boy=document.getElementByName("ck1");
var gril=document.getElementByName("ck2");
if(u=="")
{
alert("请输入");
return false;
}else
{
return true;
}
if(boy=="")
{
alert("请选择");
return false;
}else {return true;}
}
</script>
<body>
<form id="form1" name="form1" method="get" action="jieshou.asp" >
<input name="txtU" type="text" id="txtU" />
<input name="ck1" type="checkbox" id="ck1" value="男" />男
<input name="ck2" type="checkbox" id="ck2" value="女" />女
<input type="submit" name="btnS" id="btnS" value="提交" onclick="return check()" /></form></body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!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=gb2312" />
<title>无标题文档</title>
</head>
<script language="javascript">
function check()
{
var u=document.getElementById("txtU");
var boy=document.getElementByName("ck1");
var gril=document.getElementByName("ck2");
if(u=="")
{
alert("请输入");
return false;
}else
{
return true;
}
if(boy=="")
{
alert("请选择");
return false;
}else {return true;}
}
</script>
<body>
<form id="form1" name="form1" method="get" action="jieshou.asp" >
<input name="txtU" type="text" id="txtU" />
<input name="ck1" type="checkbox" id="ck1" value="男" />男
<input name="ck2" type="checkbox" id="ck2" value="女" />女
<input type="submit" name="btnS" id="btnS" value="提交" onclick="return check()" /></form></body>
</html>
var gril=document.getElementById("ck2").value;
var boy=document.getElementsByName("ck1")[0].value;
var gril=document.getElementsByName("ck2")[0].value;
{
alert("请输入");
return false;
}else
{
return true;
}
if(boy=="")
.....逻辑也错了
function check()
{
var u=document.getElementById("txtU").value;
var boy=document.getElementsByName("ck1")[0].checked;
var gril=document.getElementsByName("ck2")[0].checked;
if(u=="") {
alert("sss");
return false;
}
if(!boy && !gril) {
alert("bbb");
return false;
}
return true;
}
</script>
function check()
{
var u=document.getElementById("txtU").value;
var boy=document.getElementsByName("ck1").checked;
var gril=document.getElementById("ck2").checked;if(u=="") {
alert("请输入");
return false;
}
if(!boy && !gril) {
alert("请选择");
return false;
}
return true;
}
</script>