Home > Web Front-end > JS Tutorial > Solution to the problem of dynamically changing the src attribute of img with javascript and the image is not displayed_Image special effects

Solution to the problem of dynamically changing the src attribute of img with javascript and the image is not displayed_Image special effects

WBOY
Release: 2016-05-16 18:18:19
Original
2260 people have browsed it

First, let’s talk about the occurrence of this bug. The page contains

Copy code The code is as follows:
Such an a tag, The JS code in onclick is to change the src attribute of the img tag with the id of current to achieve the effect of dynamically switching images. But unfortunately: IE dynamically changes the path of the image, but the image is not displayed. You have to right-click and "Show Image" to see the changed image. I don't know the reason, but it is said to be or Using the a tag in this way does not prevent the a tag from triggering some behavior, causing IE6 to mistakenly think that the page has been refreshed or redirected, and interrupts All current connections are blocked, so that the loading of new pictures is aborted (I don’t know whether it is true or not). Regardless of whether the reason is true or false, let’s talk about the solution first

Simple solution:
Copy code The code is as follows:


Just add return false; after the code
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