Update 2 exact same images source using javascript [duplicate]
Possible Duplicate:
Update 2 exact same images source using javascript
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开发者_如何学JAVA 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.
I tried to remove id and use class but still this does nothing
$('.captcha').src='cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1;
because saying undefined reference.
You're almost there! You need to use .attr
in jQuery, as there is no .src
method
$('.captcha').attr('src', 'cryptographp.html?cfg=0&&'+Math.round(Math.random(0)*1000)+1);
Ensure your two <img>
has the class captcha
the correct syntax is
$(".captcha").attr('src',"image url")
精彩评论