使用javascript更新2完全相同的图像源 [英] Update 2 exact same images source using javascript

查看:85
本文介绍了使用javascript更新2完全相同的图像源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用称为Cryptographer captchan.fr网站的PHP验证码

I using PHP captcha called Cryptographer captchan.fr site

我需要在同一页面上使用2验证码但我有问题它们确实生成了但是当我点击刷新时只有第一个刷新,刷新代码看起来像这样。

I need to use 2 captcha on same page but i have problem they do get generated but when i click refresh only first one refreshes, refresh code looks like this.

document.images.captcha.src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;

我试过这段代码,但它只适用于第一个

I tried this code but it only works for first one anyway

document.getElementById('captcha').src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;

现在我想做类似这样的事情我为图片添加了name =captcha但这不是出于某种原因工作有人可以帮我解决吗?

Now I wanted to do something like this I added name="captcha" to image but this does not work for some reason can someone help me fix it?

document.getElementsByName('captcha').src='cryptographp.html?cfg=0&&+Math.round(Math.random(0)*1000)+1;

如果这更容易,我也有附加到页面的jquery。

I also have jquery attached to page if thats easier.

推荐答案

页面上不能有多个具有相同ID的元素。这可能就是为什么它只能击中第一个。如果你为两个名为captcha的图像添加一个类,你可以使用jQuery轻松完成:

You can't have more than one element with same ID on page. That may be why it's only hitting the first one. If you add a class to both images called "captcha" you can easily do this with jQuery:

$('.captcha').attr('src', 'cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1);

这篇关于使用javascript更新2完全相同的图像源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆