我想用一个js文件验证表单,使其在提交时不为空。可是最后为什么不起效果呢,请各位看一下是我写错了还是配错了 谢谢哈
success.jsp(在WebRoot目录下)的表单相关代码如下:
<head>
<base href="<%=basePath%>">
<title>My JSP 'success1.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
<!--
a:link {font-family:"宋体";text-decoration:none}
a:visited {font-family:"宋体";text-decoration:none}
a:hover {font-family:"宋体";text-decoration:none}
-->
</style>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" language="javascript" src="js/checkForm.js"></></script>
</head>
</head>
<body >
<center>
<form name="login" action="<%= request.getContextPath()%>/CheckLoginServlet" method="post" >
<table width="80%" border="1">
<tr>
<td align="center" colspan="2"><img src="images/regsucc.PNG" width="216" height="44" /></td>
</tr>
<tr>
<td width="50%"><div align="right">用户名:</div></td>
<td width="50%"><input type="text" name="username" /></td>
</tr>
<tr>
<td><div align="right">密码:</div></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input type="submit" name="login" value="登录" onclick="checkForm(login)"/></td>
<td ><div align="left"><a href="register.jsp"><img src="images/rereg.PNG" width="90" height="32" border="0"/></a></div></td>
</tr>
</table></form>js文件在WebRoot目录下的js文件夹里面,checkForm.js的代码如下
function checkForm(form){
if(isEmpty(form.username.value) || isEmpty(form.password.value)){
alert("请把登录信息填写完整!");
return false;
}
}
success.jsp(在WebRoot目录下)的表单相关代码如下:
<head>
<base href="<%=basePath%>">
<title>My JSP 'success1.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
<!--
a:link {font-family:"宋体";text-decoration:none}
a:visited {font-family:"宋体";text-decoration:none}
a:hover {font-family:"宋体";text-decoration:none}
-->
</style>
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript" language="javascript" src="js/checkForm.js"></></script>
</head>
</head>
<body >
<center>
<form name="login" action="<%= request.getContextPath()%>/CheckLoginServlet" method="post" >
<table width="80%" border="1">
<tr>
<td align="center" colspan="2"><img src="images/regsucc.PNG" width="216" height="44" /></td>
</tr>
<tr>
<td width="50%"><div align="right">用户名:</div></td>
<td width="50%"><input type="text" name="username" /></td>
</tr>
<tr>
<td><div align="right">密码:</div></td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td align="right"><input type="submit" name="login" value="登录" onclick="checkForm(login)"/></td>
<td ><div align="left"><a href="register.jsp"><img src="images/rereg.PNG" width="90" height="32" border="0"/></a></div></td>
</tr>
</table></form>js文件在WebRoot目录下的js文件夹里面,checkForm.js的代码如下
function checkForm(form){
if(isEmpty(form.username.value) || isEmpty(form.password.value)){
alert("请把登录信息填写完整!");
return false;
}
}
解决方案 »
- ReSultSet cannot be resolved to a type的问题在线等。。。。。
- spring bind问题
- 怎么将地址栏加密
- spring2.0+hibernate3.0问题???
- AuthenticationCredentialsNotFoundException怎么解决?
- jsp和aspx共用一个80端口
- QQ 群发 QQ协议 批量加好友 我已经做发来了,并能批量登陆加好友,批量群发,你们谁有做过这类似的吗,交流一下。呵呵。我的QQ是 309159808
- WSDD部暑WebService时出错,请大侠帮助```
- struts Action传参数给servlet问题
- 一个关于java的小问题要请教?
- 各位大侠,如何判断新员工工作量不能超出老员工工作量20%?急
- 有人做过基于LUCENE搜索引擎方面的东西吗?求指导.
你的方法放错了!
你的type是submit、一点击它就提交表单了!
应该在<form>标签中加入onsubmit="return checkForm(login)"方法!
然后在checkForm(login)方法内部给一个返回值true或者false。
这样、当方法返回false的时候、表单就不会提交了!