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>

posted on 2014-04-14 10:55  wongdavid  阅读(882)  评论(0编辑  收藏  举报