Update 2 exact same images source using javascript

元气小坏坏 提交于 2019-12-20 06:45:06

问题


I using PHP captcha called Cryptographer captchan.fr site

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;

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;

I also have jquery attached to page if thats easier.


回答1:


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);


来源:https://stackoverflow.com/questions/5958617/update-2-exact-same-images-source-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!