用javascript做注册验证

来源:百度知道 编辑:UC知道 时间:2024/06/17 05:13:02
我想用javascript做前台的登陆验证,我想实现 在输入框旁边就会显示各种提示信息。听老师说要用javascript去调用层来实现。我不会,请大家帮帮我。谢谢!

给你写个简单的,一个文本框,一个密码框,验证两个都不能为空的。
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script>
function checkForm()
{
var f = document.forms[0];
if(f.username.value=='')
{
document.getElementById("userNameInfo").style.display="block";
return false;
}
if(f.password.value=='')
{
document.getElementById("passwordInfo").style.display="block";
return false;
}
return true;
}
</script>
</head>

<body>
<form action="#" method="post" onsubmit="return checkForm()">
用户名:<input