码迷,mamicode.com
首页 > 其他好文 > 详细

点击按钮改变多张图片

时间:2014-12-02 18:57:07      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   ar   color   sp   for   on   

bubuko.com,布布扣

 

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
li{
 list-style-type: none;
 width: 114px;
 height: 140px;
 background: url(‘./normal.png‘);
 margin-right: 20px;
 float:left;
}

</style>
<script>
 window.onload = function(){
  var aLi = document.getElementsByTagName(‘li‘);  //得到li元素
  var onOff = true;    //定义一个变量
  for(var i=0;i<aLi.length;i++){
   aLi[i].onOff = true;
   aLi[i].onclickr = function(){
    if (onOff) {  //  判断
     this.style.background = "url(./active.png)";    //this 代表  aLi[i]
     onOff = false;      //改变变量
       }else{
        this.style.background = "url(./normal.png)";
     onOff = true;
       }
   };
  }
 };
</script>
</head>
 
<body>
    <ul>
     <li></li>
     <li></li>
     <li></li>
     <li></li>
    </ul>
</body>
</html>

点击按钮改变多张图片

标签:style   blog   http   io   ar   color   sp   for   on   

原文地址:http://www.cnblogs.com/zzg521/p/4138010.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!