发布网友
共5个回答
热心网友
验证一般都连接数据库的.这里只是作个示范.用户名:admin 密码:123
--------------------
login.html文件:
<html>
<head>
<title>登陆</title>
</head>
<script language="javascript">
function check()
{
if (document.form1.username.value=="")
{
document.getElementById("usernameTip").innerHTML="<font color=red>请输入用户名</font>";
document.form1.username.focus();
return false;
}
else
document.getElementById("usernameTip").innerHTML="";
if (document.form1.userpwd.value=="")
{
document.getElementById("userpwdTip").innerHTML="<font color=red>请输入密码</font>";
document.form1.userpwd.focus();
return false;
}
else
document.getElementById("userpwdTip").innerHTML="";
if (document.form1.username.value!="admin")//============用户名:admin =========
{
document.getElementById("ischeckTip").innerHTML="<font color=red>用户名不存在</font>";
document.form1.username.focus();
return false;
}
if (document.form1.userpwd.value!="123")//=======密码:123 =====
{
document.getElementById("ischeckTip").innerHTML="<font color=red>密码错误</font>";
document.form1.userpwd.focus();
return false;
}
return true;
}</script>
<body>
<form name="form1" method="post" action="index.html">
<table width="348" align="center" cellpadding="1" cellspacing="1" bgcolor="#99CCFF">
<tr>
<td width="59" bgcolor="#FFFFFF">用户名:</td>
<td width="105" bgcolor="#FFFFFF"><input name="username" type="text" size="15" bgcolor="#FFFFFF"></td>
<td width="174" id="usernameTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF">密 码:</td>
<td bgcolor="#FFFFFF"><input name="userpwd" type="password" size="15" bgcolor="#FFFFFF"></td>
<td id="userpwdTip" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td bgcolor="#FFFFFF"> </td>
<td bgcolor="#FFFFFF"><input type="submit" name="Submit1" value="提交" onClick="return check()">
<input type="reset" name="Submit2" value="重置"></td>
<td id="ischeckTip" bgcolor="#FFFFFF"> </td>
</tr>
</table>
</form>
</body>
</html>
------------------------------------------
index.html文件:
<html>
<head>
<title>欢迎</title>
</head>
<body>
登陆成功
</body>
</html>
热心网友
关键就是在 form 标签中加入 onsubmit="return someFunc()"
这里的 someFunc() 是处理函数,你可以自己定义该函数,
并且,如果该函数返回 true 则表单立即提交到服务器,
如果该函数返回 false 则表单不会被提交.
直到该函数返回 true 为止
<form name="form1" action="check.php" method="post" onsubmit="return checkForm(this)">
用户: <input type="text" name="username" id="username" />
密码: <input type="password" name="password" id="password" />
<input type="submit" value="提交" />
</form>
<script type="text/javascript">
<!--
function checkForm(srcForm)
{
if (srcForm.username == null || srcForm.username.value == '')
{
alert("没有填写用户名"); return false;
}
if (srcForm.password == null || srcForm.username.value == '')
{
alert("没有填写密码"); return false;
}
alert("你的资料填写完整, 现在转向服务器端认证!"); return true;
}
}
//-->
</script>
热心网友
用ASP写,不过是在按了提交后
代码如下
dim name,pwd
const name1="你规定的名字",pwd1="你规定的密码"
name=request.form("文本区域的名字(假设为NAME)")
pwd=request.form("密码框的名字(假设为PWD)")
if (name=name1) and (pwd=pwd1) then
request.redirect("你想要转到的页面")
end if
热心网友
不是很懂js。不过用php也很简单的嘛
if(name = & password= ){
}
热心网友
js就行的