导航:首页 > 编程语言 > js点击验证码刷新

js点击验证码刷新

发布时间:2023-03-02 19:35:03

Ⅰ 高手帮看下这个js,向手机发送验证码,60秒倒计时,如何在这60秒内刷新页面这60秒还有效,60秒后才可重发

js页面一刷新就什么都没 除非你写cookie 刷新的完成后再读取cookie

Ⅱ 用Jquery设置点击图片刷新验证码,但是只能点击一次,第二次就会失效,感觉是获取按钮对象的问题

$("#change").click(function () {
let date= new Date().getTime();
$("#checkCode").setAttribute("src", /day15/checkCodeServlet?"+date);
});
这样?

Ⅲ 写了个JS脚本来刷新验证码 可是总是刷不出来 求高手

<img src='for2.php?'>

js 更换img的src时 在for2.php后面加 随机字符。如 "for2.php?"+mathi.random();

Ⅳ jsp页面该如何刷新验证码

(1)jsp代码
<img id = "img_authcode" src="${ctx}/account/authcode" /><a href="javascript:;" onclick="javascript:document.getElementById('img_authcode').setAttribute('src', '${ctx}/account/authcode?' + Math.random())">换一换</a>

(2)java代码(该代码为我自己框架代码,跟servlet写法不一样的我都给你注释了):
public View authcode() throws IOException {
HttpServletResponse response = PuffContext.getResponse();//获取response
response.setContentType("image/jpeg");
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache");
response.setDateHeader("Expires", 0);
String authCode = AuthCodeUtil.getRandom(4); //获取验证码,代码在下面(3)
System.out.println("生成随机码:" + authCode);
PuffContext.getSession().setAttribute("session_authcode", authCode);//把该验证码存储在session
ServletOutputStream output = response.getOutputStream();
AuthCodeUtil.draw(output, authCode);
output.flush();
output.close();
return ViewFactory.nullView();//返回null
}

(3)///////////////////////////下面为生成验证码类////////////////////////////////////

public class AuthCodeUtil {
private final static Random random = new Random();
// 随机字体样式
private final static int[] fontStyle = { Font.HANGING_BASELINE, Font.ITALIC, Font.LAYOUT_LEFT_TO_RIGHT, Font.LAYOUT_NO_LIMIT_CONTEXT,
Font.LAYOUT_NO_START_CONTEXT, Font.LAYOUT_RIGHT_TO_LEFT };

/**
* 画随机码图
*
* @param out
* @param width
* @param height
* @throws IOException
*/
public static void draw(OutputStream out, String value) throws IOException {
int width = 80, height = 30;
BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D g = (Graphics2D) bi.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, width, height);
g.drawRect(1, 1, width - 2, height - 2);
for (int i = 0; i < 10; i++) {
g.setColor(randColor(150, 250));
g.drawOval(random.nextInt(110), random.nextInt(24), 5 + random.nextInt(10), 5 + random.nextInt(10));
}
int n = (int) (Math.random() * 6);
Font mFont = new Font("Arial", fontStyle[n], 23);
g.setFont(mFont);
g.setColor(randColor(10, 240));
g.drawString(value, 10, 21);// 随机数,水平距离,垂直距离
ImageIO.write(bi, "png", out);
}

private static Color randColor(int fc, int bc) {// 给定范围获得随机颜色
if (fc > 255)
fc = 255;
if (bc > 255)
bc = 255;
int r = fc + random.nextInt(bc - fc);
int g = fc + random.nextInt(bc - fc);
int b = fc + random.nextInt(bc - fc);
return new Color(r, g, b);
}

public static void main(String[] args) throws IOException {
FileOutputStream out = new FileOutputStream("d:\\aa.png");
draw(out, getRandom(4));
}

public static String getRandom(int size) {// 随机字符串
char[] c = { '1', '3', '5', '6', '7', '8', '9' };
StringBuffer sb = new StringBuffer();
for (int i = 0; i < size; i++)
sb.append(c[Math.abs(random.nextInt()) % c.length]);
return sb.toString();
}

}

Ⅳ JS刷新验证码的问题

没有设置事件怎么刷新呢?? 你如果想当点击的时候刷新要加click事件.这里是获取来的元素也就是imgCode.onclick = function () {
这里面写你的代码
}

Ⅵ JavaScript 刷新验证码失败

估计是有JS的代码错误导致部分JS功能无法正常使用了,建议你在浏览器访问时按F12出来控制台查看下是否有错误的JS提示。

目测出问题的地方有两处:

1、onload="btn.disable=false;"
2、document.getElementById("btn").isDisable=true;
把这两个代码删掉试试。

阅读全文

与js点击验证码刷新相关的资料

热点内容
哪里能学程序编程 浏览:647
微信里面的文件储存在哪个目录 浏览:745
高仿苹果5s屏幕显示清楚吗 浏览:897
若有以下程序void 浏览:432
大数据主体有哪些 浏览:961
如何学习编程的优点 浏览:906
最新版本手机qq 浏览:463
简述在word 浏览:528
qq怎么清楚历史记录防止被盗 浏览:263
发送手机里的录音文件在哪里 浏览:866
js获取下一个兄弟元素 浏览:293
js模板引擎原理 浏览:72
linuxo文件运行 浏览:713
什么免费备份数据 浏览:342
测量大师导入底图找不到文件 浏览:313
小红伞安装程序要求版本6 浏览:799
全民k歌pcm文件夹 浏览:224
c图片写入数据库 浏览:466
c串口程序 浏览:500
中农金融注册app有哪些 浏览:629

友情链接