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影片教學
以上是javascript如何改變圖片連結位址的詳細內容。更多資訊請關注PHP中文網其他相關文章!