驗證碼重新整理
阿新 • • 發佈:2018-11-09
通過拼接字串實現重新整理
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>
注:
- 拼接隨機字串(d為任意字元)${pageContext.request.contextPath}/captcha/createCaptcha?d="+new Date().getTime();
- 引入驗證碼 src="<s:url action='createCaptcha' namespace='/captcha' />"
- 阻止連結重新整理頁面 javascript:void(0)