jquery实现无刷新验证码的简单实例(3)

function changeImg(){ var imgSrc = $("#imgObj"); var src = imgSrc.attr("src"); imgSrc.attr("src",chgUrl(src)); } //时间戳 //为了使每次生成图片不一致,即不让浏览器读缓存,所以需要加上时间戳 function chgUrl(url){ var timestamp = (new Date()).valueOf(); url = url.substring(0,17); if((url.indexOf("&")>=0)){ url = url + "×tamp=" + timestamp; }else{ url = url + "?timestamp=" + timestamp; } return url; } function isRightCode(){ var code = $("#veryCode").attr("value"); code = "c=" + code; $.ajax({ type:"POST", url:"resultServlet", data:code, success:callback }); } function callback(data){ $("#info").html(data); } function changeImg(){ var imgSrc = $("#imgObj"); var src = imgSrc.attr("src"); imgSrc.attr("src",chgUrl(src)); } //时间戳 //为了使每次生成图片不一致,即不让浏览器读缓存,所以需要加上时间戳 function chgUrl(url){ var timestamp = (new Date()).valueOf(); url = url.substring(0,17); if((url.indexOf("&")>=0)){ url = url + "×tamp=" + timestamp; }else{ url = url + "?timestamp=" + timestamp; } return url; } function isRightCode(){ var code = $("#veryCode").attr("value"); code = "c=" + code; $.ajax({ type:"POST", url:"resultServlet", data:code, success:callback }); } function callback(data){ $("#info").html(data); }

verifyCode.jsp

Html代码

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="https://www.jb51.net/js/verifyCode.js"></script> <script type="text/javascript" src="https://www.jb51.net/js/jquery.js"></script> <title>test verify code</title> </head> <body> <input type="text"/> <img alt="" src="https://www.jb51.net/verifyCodeServlet"/> <a href="#">换一张</a> <input type="button" value="验证"/> <div></div> </body> </html>

以上这篇jquery实现无刷新验证码的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpjgw.html