Javascript method to change the image link address: [window.onload = function () {ImageSrc();} function ImageSrc() { var imgs = document.getEleme...].
#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!