Home  >  Article  >  Web Front-end  >  How to change the image link address with javascript

How to change the image link address with javascript

王林
王林Original
2021-11-09 15:43:347259browse

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>

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!

Statement:
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