javascript改变图片链接地址的方法:【window.onload = function () {ImageSrc();} function ImageSrc() { var imgs = document.getEleme...】。 本文操作环境:windows10系统、javascript 1.8.5、thinkpad t480电脑。 JavaScri
javascript改变图片链接地址的方法:【window.onload = function () {ImageSrc();} function ImageSrc() { var imgs = document.getEleme...】。
本文操作环境:windows10系统、javascript 1.8.5、thinkpad t480电脑。
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>
推荐学习:javascript视频教程