日期:2014-05-16  浏览次数:21019 次

为什么 运行到这里时document.getElementById("indicator").style.display="block";显示是缺少对象的 ??
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
%>
<!DOCTYPE HTML PUBLIC"-//W3C//DTC HTML 4.01 Transitional//EN">
<html>
<head>
  <script type='text/javascript' src='<%=path %>/dwr/interface/loginService.js'></script>
  <script type='text/javascript' src='<%=path %>/dwr/engine.js'></script>
  <script type='text/javascript' src='<%=path %>/dwr/util.js'></script>
   
  <script language="javascript">
  function check1()
  {
  if(document.ThisForm.userName.value=="")
  {
  alert("请输入用户名");
  document.ThisForm.userName.focus();
  return false;
  }
  if(document.ThisForm.userPw.value="")
  {
  alert("请输入密码");
  return false;
  }
  document.getElementById("indicator").style.display="block";
  loginService.login(document.ThisForm.userName.value,document.ThisForm.userPw.value,0,callback);
  }
  function callback(data)
  {
  document.getElementById("indicator").style.display="none";
  if(data=="no")
  {
  alert("用户名或密码错误");
  }
  if(data=="yes")
  {
  alert("通过验证,系统登录成功");
  window.location.href="<%=path%>/loginSuccess.jsp";
  }
  }
  </script>
</head>
<body>
  <span>基于JSP的论坛网站</span></td>
  <FORM name="ThisForm" action="<%=path %>/adminLogin.action" method=post>
  <td>用户名:</td>
  <td><input name="userName" value=""></td>
  <td>密码:</td>
  <td><input name="userPw"></td>
  <input name="button" type="button" id="Submit" value="登录" onClick="check1()">
  <input name="cs" type="reset" id="cs" value="重置"></td>
  </body>
</html>

------解决方案--------------------
你的html代码里面就没有id为indicator的对象。。加上,form标签也没闭合,td乱嵌套。
JScript code

//if(document.ThisForm.userPw.value="")
if(document.ThisForm.userPw.value=="")////是==,不是=赋值
  {
  alert("请输入密码");
  return false;
  }

------解决方案--------------------
就没看到你有这个以这个名称命名的id。