当前位置:编程学习 > JS >>

jsp里写了javascript,但运行jsp时没有提示运行脚本,也就是javascript不起作用,怎么回事

这是jsp文件

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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>
<style type="text/css">
<!--
.STYLE1 {
 font-size: 36px;
 color: #0066FF;
}
.STYLE3 {color: #0066FF; font-size: 18px; }
.STYLE4 {color: #CC0033}
-->
</style>
<script language="javascript">
function check()
{
if(form1.username.value=="")
{
  alert("用户名不能为空,请输入用户名!");
  form1.usrname.focus();
  return false;
}
if(form1.password.value=="")
{
  alert("用户密码不能为空!请输入密码!");
  form1.password.focus();
  return false;
}
if(form1.Rand.value=="")
{
   alert("用户验证码不能为空,请输入正确的验证码!");
   form1.Rand.value=="";
   return false;
}
if(form1.Rand.value.indexOf("123456789")==-1)
{
  alert("验证码必须为整数!");
  form1.password.focus();
  return false;
}

}
</script>
</head>

 

<body>
<form id="form1" name="form1" method="post" action="servlet/logincheck" OnSubmit="return check()">
  <table width="1000" height="368" border="0" align="center">
    <tr>
      <td colspan="6"><div align="center" class="STYLE1">超市进销存管理系统</div></td>
    </tr>
    <tr>
      <td width="128" rowspan="3"><img src="image/lock_open.png" width="128px" height="128px" /></td>
      <td width="142" height="44"><div align="right" class="STYLE3">用户名:</div></td>
      <td width="243"><label>
        <input type="text" name="username" />
      </label></td>
      <td width="218"> </td>
      <td colspan="2"> </td>
    </tr>
    <tr>
      <td height="48"><div align="right" class="STYLE3">密 码:</div></td>
      <td><label>
        <input type="password" name="password" />
      </label></td>
      <td> </td>
      <td colspan="2"> </td>
    </tr>
    <tr>
      <td height="39"><div align="right" class="STYLE3">验证码:</div></td>
      <td><label>
        <input type="text" name="Rand" >
        <script>document.write("<img border=0 src='image.jsp?Rand="+Math.random()*10000+"'>");</script>
      </label></td>
      <td> </td>
      <td width="85"><label>
        <input type="submit" name="Submit" value="登陆" />
      </label></td>
      <td width="158"><label>
        <input type="reset" name="reset" value="重置" />
      </label></td>
    </tr>
    <tr>
      <td height="72" colspan="6"><div align="center">
        <p class="STYLE4">版权所有CopyRight  © All Rights Reserved</p>
        </div></td>
    </tr>
  </table>
</form>
</body>
</html>

追问:有啊,我写在form表单的OnSubmit里了

<form id="form1" name="form1" method="post" action="servlet/logincheck" OnSubmit="return check()">

答案:  你都没有用的你写的JS啊。。。<input type="submit" name="Submit" value="登陆" />这里面你的加上啊

你好   你的JS有脚本错误  所以验证时无法返回正确的布尔值

请看check方法的第一个判断

if(form1.username.value=="")
{
  alert("用户名不能为空,请输入用户名!");
  //form1.usrname.focus(); 这里有问题  返回默认真值 所以仍会提交

form1.username.focus(); //应该是这样
  return false;
}

上一个:JavaScript取名为什么带"Java"字样
下一个:HTLM脚本语言问题

CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,