问题
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