1. 程式人生 > >驗證碼重新整理

驗證碼重新整理

通過拼接字串實現重新整理

function reimg(){
    var imgVcode =	document.getElementById("imgVcode");
    imgVcode.src = "${pageContext.request.contextPath}/captcha/createCaptcha?d="+new Date().getTime();  
}

繫結事件onclick,點選時呼叫reimg()

<tr>
	<td valign="top" class="w1">
		驗證碼:
	</td>
	<td>
	    <img class="yzm_img" id='imgVcode' src="<s:url action='createCaptcha' namespace='/captcha' />" />
	    <input name="code" type="text" id="txtVerifyCode" class="yzm_input"/>
	    <div class="text_left t1">
	    	<p class="t1">
	    		<span id="vcodeValidMsg">請輸入圖片中的四個字母。</span>								
	    		<a href="javascript:void(0);" onclick="reimg()" >看不清楚?換個圖片</a>
		    </p>
	    </div>
	</td>
</tr>

注: 

  1. 拼接隨機字串(d為任意字元)${pageContext.request.contextPath}/captcha/createCaptcha?d="+new Date().getTime(); 
  2. 引入驗證碼   src="<s:url action='createCaptcha' namespace='/captcha' />" 
  3. 阻止連結重新整理頁面   javascript:void(0)