1. When clicking a button, change the picture in the picture field.
The code copy is as follows:
<img id="randimg" src="/servlet/CreateValidateNum" />
<span style="cursor:hand" onclick="reflush();return false;">can't see clearly</span>
<script>
function reflush()
{
document.getElementById(randimg).src="/servlet/CreateValidateNum";
}
</script>
2. Explanation
"servlet/CreateValidateNum" is a servlet written by JAVA. The servlet prints the picture
3. Problems that arise
The image modification under IE6 is normal, but it is not refreshed under IE7 and Firefox
4. Situation analysis
If the new picture is different from the old picture address, the effect will come out. That is: the picture has changed.
But functions like "verification code". The addresses of the old and new pictures are the same.
In view of the above situation, it is suspected that the browser may automatically read the cache because the image address is the same.
5. Solution
Change javascript to this:
document.getElementById(randimg).src="/servlet/CreateValidateNum?"+Math.random();
That is: the access address is different each time, because there is a random number added. So the problem is solved