这是我打开页面时获取验证码代码
<img id="imgwd" src="servlet/ValidateServlet" onclick="getOther()" />
我想实现单击一下验证码后换一张新的验证码,是这么写的
function   getOther(){ 
    var   img   =document.getElementById( "imgwd "); 
    img.src= "servlet/ValidateServlet"+ new Date().getTime;
}
这两个在同一个jsp中,现在img.src= "servlet/ValidateServlet"+ new Date().getTime;这个没好使,现在单击没有效果,哪位大侠帮帮忙~~~~~~

解决方案 »

  1.   


    <%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
    <%@ taglib uri="/struts-tags" prefix="s"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
    + request.getServerName() + ":" + request.getServerPort()
    + path + "/";
    %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>"> <title>登录</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">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    <script type="text/javascript" src="jscript/jsutil.js"></script>
    </head> <body>
    <center>
    <h3>
    请输入用户名和密码来登录
    </h3>
    单击此处
    <a href="regist.jsp">注册</a>
    <br>
    <a href="forgetPwd1.jsp">忘记密码?</a>
    <s:form action="login.action" method="post">
    <s:textfield name="username" label="用户名"></s:textfield>
    <s:password name="password" label="密码"></s:password>
    <s:textfield name="code" label="验证码"></s:textfield>
    <s:submit value="提交" />
    </s:form>
    <label for="rand">验证码:</label>
    <img src="rand.action" id="rand" />
    <a href="javascript:void(0)"
    onclick="changeValidateCode();return false;">看不清,换一张</a>
    </center>
    </body>
    </html>
    function changeValidateCode() {
    var timenow = new Date().getTime();
    document.getElementById("rand").src = "rand.action?d=" + timenow;
    }
      

  2.   

    javascript:void(0)这个是什么作用的?我按你这样试了下没好使啊
      

  3.   

    function getOther(){  
      var img =document.getElementById( "imgwd ");  //这里后面多了个空格
      img.src= "servlet/ValidateServlet"+ new Date().getTime;  
    // 你的拦截是哪个呀? 
    // img.src= "servlet/ValidateServlet?i="+ new Date().getTime;  ?
    }
      

  4.   

    img.src= "servlet/ValidateServlet?i="+ new Date().getTime; 这个后面加时间我不是很理解,他是做什么用的 我servlet接它后怎么操作?