HTML验证用户密码不能为空的代码不好使,我什么地方写错了,麻烦给看一下
<!DOCTYPEhtml><html><head><title>COCOP登录画面</title><metahttp-equiv="Content-Type"conte...
<!DOCTYPE html>
<html>
<head>
<title>COCOP登录画面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function mycheck(){
if(form1.name.value==""){
alert("用户名称不能为空!!");form1.name.focus();return false;
}
if(form1.password.value==""){
alert("用户密码不能为空!!");form1.password.focus();return false;}
}
if(form1.telno.value==""){
alert("用户密码不能为空!!");form1.telno.focus();return false;}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<center><img width="150" height="60" src="image/pic2.bmp" ></center>
<center><hr size="3" width="150" color="brown"></center>
<center>用户名:</label><input type="text" name="name" value="" size=11 maxlength=10 style=3></center>
<center>密 码:<input type="password" name="password" value="" size=11 maxlength=10 style=3 ></center>
<center>手机号:<input type="text" name="telno" value="" size=11 maxlength=11 style=3 ></center>
<center><input type="submit" value="登录" name="send" onclick="return mycheck()">
<input type="submit" value="取消" name="cancel" onclick="form.action='search.php';form.submit();"></center>
<center><hr size="3" width="150" color="brown"></center>
<center>©2010 Navi-p.com Corpo-</center>
<center>ration.All Rights Reserved.</center>
</form>
</body>
</html> 展开
<html>
<head>
<title>COCOP登录画面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function mycheck(){
if(form1.name.value==""){
alert("用户名称不能为空!!");form1.name.focus();return false;
}
if(form1.password.value==""){
alert("用户密码不能为空!!");form1.password.focus();return false;}
}
if(form1.telno.value==""){
alert("用户密码不能为空!!");form1.telno.focus();return false;}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<center><img width="150" height="60" src="image/pic2.bmp" ></center>
<center><hr size="3" width="150" color="brown"></center>
<center>用户名:</label><input type="text" name="name" value="" size=11 maxlength=10 style=3></center>
<center>密 码:<input type="password" name="password" value="" size=11 maxlength=10 style=3 ></center>
<center>手机号:<input type="text" name="telno" value="" size=11 maxlength=11 style=3 ></center>
<center><input type="submit" value="登录" name="send" onclick="return mycheck()">
<input type="submit" value="取消" name="cancel" onclick="form.action='search.php';form.submit();"></center>
<center><hr size="3" width="150" color="brown"></center>
<center>©2010 Navi-p.com Corpo-</center>
<center>ration.All Rights Reserved.</center>
</form>
</body>
</html> 展开
展开全部
修改好了的,你在if(form1.password.value==""){
alert("用户密码不能为空!!");form1.password.focus();return false;}
}
函数中多了个}
完整的代码
<!DOCTYPE html>
<html>
<head>
<title>COCOP登录画面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function mycheck(){
if(form1.name.value==""){
alert("用户名称不能为空!!");
form1.name.focus();
return false;
}
if(form1.password.value==""){
alert("用户密码不能为空!!");
form1.password.focus();
return false;
}
if(form1.telno.value==""){
alert("用户密码不能为空!!");
form1.telno.focus();
return false;
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<center><img width="150" height="60" src="image/pic2.bmp" ></center>
<center><hr size="3" width="150" color="brown"></center>
<center>用户名:</label><input type="text" name="name" value="" size=11 maxlength=10 style=3></center>
<center>密 码:<input type="password" name="password" value="" size=11 maxlength=10 style=3 ></center>
<center>手机号:<input type="text" name="telno" value="" size=11 maxlength=11 style=3 ></center>
<center><input type="submit" value="登录" name="send" onclick="return mycheck()">
<input type="submit" value="取消" name="cancel" onclick="form.action='search.php';form.submit();"></center>
<center><hr size="3" width="150" color="brown"></center>
<center>©2010 Navi-p.com Corpo-</center>
<center>ration.All Rights Reserved.</center>
</form>
</body>
</html>
alert("用户密码不能为空!!");form1.password.focus();return false;}
}
函数中多了个}
完整的代码
<!DOCTYPE html>
<html>
<head>
<title>COCOP登录画面</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script language="javascript">
function mycheck(){
if(form1.name.value==""){
alert("用户名称不能为空!!");
form1.name.focus();
return false;
}
if(form1.password.value==""){
alert("用户密码不能为空!!");
form1.password.focus();
return false;
}
if(form1.telno.value==""){
alert("用户密码不能为空!!");
form1.telno.focus();
return false;
}
}
</script>
</head>
<body>
<form name="form1" method="post" action="" >
<center><img width="150" height="60" src="image/pic2.bmp" ></center>
<center><hr size="3" width="150" color="brown"></center>
<center>用户名:</label><input type="text" name="name" value="" size=11 maxlength=10 style=3></center>
<center>密 码:<input type="password" name="password" value="" size=11 maxlength=10 style=3 ></center>
<center>手机号:<input type="text" name="telno" value="" size=11 maxlength=11 style=3 ></center>
<center><input type="submit" value="登录" name="send" onclick="return mycheck()">
<input type="submit" value="取消" name="cancel" onclick="form.action='search.php';form.submit();"></center>
<center><hr size="3" width="150" color="brown"></center>
<center>©2010 Navi-p.com Corpo-</center>
<center>ration.All Rights Reserved.</center>
</form>
</body>
</html>
展开全部
<script language="javascript">
window.onload=function(){
a=document.forms['form1'];
a.onsubmit=function(){
var aa=a['name'];
var ab=a['password'];
var ac=a['telno'];
if(aa.value==""){
alert ('用户不能为空');
return false;
}else if(ab.value==""){
alert ('密码不能为空');
return false;
}else if(ac.value==""){
alert ('手机号不能为空');
return false;
}else{
return true;
}
}
}
</script>
重新写了 js的代码。
把这个复制只替换 js的代码就行!
有什么补充的可以~ 回复下。
window.onload=function(){
a=document.forms['form1'];
a.onsubmit=function(){
var aa=a['name'];
var ab=a['password'];
var ac=a['telno'];
if(aa.value==""){
alert ('用户不能为空');
return false;
}else if(ab.value==""){
alert ('密码不能为空');
return false;
}else if(ac.value==""){
alert ('手机号不能为空');
return false;
}else{
return true;
}
}
}
</script>
重新写了 js的代码。
把这个复制只替换 js的代码就行!
有什么补充的可以~ 回复下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询