<html>
<script language="javascript">
function CheckForm(){
if(document.form1.name.value.length == 0) {
alert("请输入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
</script>
<head>
</head><body>
<form action="a.php" method="post" name="form1" onSubmit="CheckForm()">
name:<input type="text" id="name" name="name"/><br>
tel:<input type="text" id="tel" name="tel"/><br>
email:<input type="text" id="email" name="emain"/><br>
<input type="submit" name="submit"/>
</form>
</body>
</html>
<script language="javascript">
function CheckForm(){
if(document.form1.name.value.length == 0) {
alert("请输入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
</script>
<head>
</head><body>
<form action="a.php" method="post" name="form1" onSubmit="CheckForm()">
name:<input type="text" id="name" name="name"/><br>
tel:<input type="text" id="tel" name="tel"/><br>
email:<input type="text" id="email" name="emain"/><br>
<input type="submit" name="submit"/>
</form>
</body>
</html>
改成
document.form1.name.focus();
function CheckForm(){
if(document.form1.name.value.length == 0) {
alert("请输入您姓名!");
document.form.name.focus();
return false;
}
return true;
}
</script>
改成
<script language="javascript">
function CheckForm(){
if(document.form1.name.value.length == 0) {
alert("请输入您姓名!");
document.form.name.focus();
return false;
}
else{
return true;
}
}
</script>
还有<script></script>代码最好放在<head></head>里面!
<html>
<script language="javascript">
function CheckForm(){
if(document.form1.name.value.length == 0) {
alert("请输入您姓名!");
document.form1.name.focus(); //form1
return false;
}
return true;
}
</script>
<head>
</head><body>
<form action="a.php" method="post" name="form1" onSubmit="return CheckForm()">//这里要return
name:<input type="text" id="name" name="name"/><br>
tel:<input type="text" id="tel" name="tel"/><br>
email:<input type="text" id="email" name="emain"/><br>
<input type="submit" name="submit"/>
</form>
</body>
</html>