Home > Web Front-end > JS Tutorial > body text

How to change the image link address with javascript

王林
Release: 2021-11-09 15:43:34
Original
7307 people have browsed it

Javascript method to change the image link address: [window.onload = function () {ImageSrc();} function ImageSrc() { var imgs = document.getEleme...].

How to change the image link address with javascript

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

The specific implementation method of changing the image link address using JavaScript:

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript">
        window.onload = function () {
            ImageSrc();
        }
        function ImageSrc() {
            var imgs = document.getElementsByClassName("ArticleBody")[0].getElementsByTagName("img");
            for (var i = 0, l = imgs.length; i < l; i++) {
                imgs[i].src = imgs[i].src.replace("gjbt", "www"); //img[i].src is the reference to the image.
            }
        }
    </script>
</head>
<body>
    <div class="ArticleBody">
        <img src="image/01.jpg" />
        <img src="image/04.jpg" />
        <img src="image/02.jpg" />
        <img src="image/03.jpg" />
    </div>
</body>
</html>
Copy after login

Recommended learning: javascript video tutorial

The above is the detailed content of How to change the image link address with javascript. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
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