网页换肤

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>网页换肤</title>
    <style type="text/css">
        *{
            margin: 0;
            padding: 0;
        }
        body{
            background: url(img/bg1.jpg) no-repeat top left;
        }
        ul{
            list-style: none;
        }
        ul li{
            width: 80px;
            height: 50px;
            margin: 10px;
            border: 1px solid #222;
            float: left;
        }
        ul li img{
            width: 80px;
            height: 50px;
            cursor: pointer;
        }
    </style>
    <script type="text/javascript">
        window.onload = function(){
            var imgs = document.getElementsByTagName("img");
            for (var i = 0; i < imgs.length; i++) {
                imgs[i].onclick = function(){
                    document.body.style.background = "url(" + this.src + ")";
                }
            };
        }
    </script>
</head>
<body>
    <ul>
        <li><img src="img/bg1.jpg"></li>
        <li><img src="img/bg2.jpg"></li>
        <li><img src="img/bg3.jpg"></li>
    </ul>
</body>
</html>     
posted @ 2019-02-10 11:05  我和我的小生活  阅读(124)  评论(0编辑  收藏  举报