首页 > 代码库 > 简单特效-切换背景图片

简单特效-切换背景图片

  HTML代码:

  <! DOCTYPE html>     <head>          <title></title>          <meat charset="utf-8">      </head>     <body>              <div class="toggle">                 <img src="http://www.mamicode.com/images/">                 <img src="http://www.mamicode.com/images/">                 <img src="http://www.mamicode.com/images/">              </div>    </body>    </html>

 CSS样式表代码:

       

   div.toggle img{width:200px;height:180px; float:right};   body{background-image:url()};

  javascript代码:

    var toggle=document.getElementsByTagName("img");    var body=document.getElementsByTagName("body") ;             toggle.onclick=function(){                body[0].style.backgroundImage="url(this.getAttribute(url))";                 }

  

   

简单特效-切换背景图片