Home > Web Front-end > JS Tutorial > Javascript modification of src problem of IMG tag_javascript skills

Javascript modification of src problem of IMG tag_javascript skills

WBOY
Release: 2016-05-16 16:54:01
Original
1208 people have browsed it

1. When a button is clicked, change the image in the image field

Copy the code The code is as follows:


cannot see clearly
<script> <br>function reflush() <br>{ <br>document.getElementById(randimg).src=" /servlet/CreateValidateNum"; <br>} <br></script>

2. Description
"servlet/CreateValidateNum" is a servlet written in JAVA. The servlet prints out pictures

3. Problems
The picture is modified normally under IE6, but it does not refresh under IE7 and Firefox

4. Situation analysis
If The new picture will have a different address than the old picture, and 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 automatically reads the cache because the image address is the same.

5. Solution
Change the javascript to this:
document.getElementById(randimg).src="/servlet/CreateValidateNum?" Math.random();
That is : The access address is different every time because a random number is added. So the problem is solved
Related labels:
src
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template