开发者

Update 2 exact same images source using javascript [duplicate]

开发者 https://www.devze.com 2023-03-04 21:08 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: Update 2 exact same images source using javascript
This question already has an answer here: Closed 11 years ago.

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")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号