只是简单的验证怎么不好使呢?急!!

JavaWorm015 2010-09-05 02:48:12

<!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=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function check(){
if(document.form1.username.value==""){
alert("请输入登陆账号!")
return false;
document.form1.username.focus();
return false;}
else if(document.form1.password.value==""){
alert("请输入密码!");
return false;
document.form1.password.focus();
return false;
}

}
</script>
</head>

<body>
<form action="2.html" method="post" name="form1" onsubmit="check()">
<table cellpadding="0" cellspacing="0" border="2" width="450" height="100" align="center">
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input type="submit" name="sub" value="确认" /></td>
<td align="center"><input type="button" name="button" value="注册" onclick="
window.location='reg.html'" /></td>
</tr>
</table>
</form>
</body>
</html>

...全文
95 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
JavaWorm015 2010-09-05
  • 打赏
  • 举报
回复
多谢。真的好使耶...哈哈
changmengmeng 2010-09-05
  • 打赏
  • 举报
回复
<!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=utf-8" />
<title>无标题文档</title>
<script language="javascript">
function check(){
if(document.form1.username.value==""){
alert("请输入登陆账号!")
return false;
document.form1.username.focus();
return false;
}
else if(document.form1.password.value==""){
alert("请输入密码!");
return false;
document.form1.password.focus();
return false;
}


}
</script>
</head>

<body>
<form action="2.html" method="post" name="form1" onsubmit="return check()">
<table cellpadding="0" cellspacing="0" border="2" width="450" height="100" align="center">
<tr>
<td align="right">用户名:</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td align="right">密码:</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input type="submit" name="sub" value="确认" onclick="return check()"/></td>
<td align="center"><input name="submit" type="button" id="submit" onclick="
window.location='reg.html'" value="注册" /></td>
</tr>
</table>
</form>
</body>
</html>

对登录进行验证,点注册应该进入注册,进入注册页,如果还要验证,再注册页再另外加
JavaWorm015 2010-09-05
  • 打赏
  • 举报
回复
为什么点击alert提示的确定后,focus()怎么不好使呢?

61,112

社区成员

发帖
与我相关
我的任务
社区描述
层叠样式表(英文全称:Cascading Style Sheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。
社区管理员
  • HTML(CSS)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧