Jquery modifies the src attribute of image, picture does not load problem __jquery

Source: Internet
Author: User

1. When you click on a button, the picture in the field to change the picture
<span style= "Cursor:hand" onclick= "Reflush (); return false;" > can not see clearly </span>
<script>
function Reflush ()
{
document.getElementById (randimg). src= "/servlet/createvalidatenum";
}
</script>

2. Notes
"Servlet/createvalidatenum" is a Java-written servlet. The servlet is printing out the picture

3. The problems that arose
The picture under IE6 is modified normally, but not refreshed under IE7 and Firefox

4. Situation Analysis
If the new picture is not the same as the old picture address, the effect will come out. That is: The picture has changed.
But like the "Captcha" feature. The address of the old and new pictures is the same.
In view of the above, it is suspected that the image address is the same, causing the browser to read the cache automatically.

5. How to Solve
Change the JavaScript to this way:
document.getElementById (randimg). src= "/servlet/createvalidatenum?" +math.random ();
That is: Each access address is not the same, because there is a random number. So the problem is solved

jquery Gets the src attribute by the method: $ ("#image"). attr ("src");

Modify the SRC attribute value: $ ("#image"). attr ("src", "image/1/gif");

------------

This method is feasible and I have tested it. Of course, I'm using jquery.

var src = "/servlet/createvalidatenum?" +math.random ();

$ ("#img_id"). attr ("src", src_v);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.