动态改变 图片的背景颜色

来源:互联网 发布:fpgrowth算法详解 编辑:程序博客网 时间:2024/06/13 00:46


动态改变 图片的背景颜色
<!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=gb2312" />
<title>使用style改变样式</title>
<style type="text/css">
li{
 font-size: 12px;
 color: #ffffff;
 background-image: url(images/bg1.gif);
 background-repeat: no-repeat;
 text-align: center;
 height: 33px;
 width:104px;
 line-height:38px;
 float:left;
 list-style:none;
 }
</style>
</head>
<script type="text/javascript">
 
 /*
  function up(thiss){
   thiss.style.backgroundImage='url(images/bg2.gif)';
 }
 function out(thiss){
   thiss.style.backgroundImage='url(images/bg1.gif)';
 }
 */
 
 //this 我自己   (当前对象 )  只上下文关系
 window.onload = function(){
  var li = document.getElementsByTagName("li");
  //循环绑定时间
  for(var i=0;i< li.length;i++){
   li[i].onmouseover = function(){
    this.style.backgroundImage='url(images/bg2.gif)';
    this.style.color='red';
   }
   li[i].onmouseout = function(){
    this.style.backgroundImage='url(images/bg1.gif)';
   }
  }
  
 }
 
</script>
<body>
<ul>
<li >资讯动态</li>
<li >产品世界</li>
<li >市场营销</li>
</ul>

</body>
</html>


<!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=gb2312" />
<title>使用className改变样式</title>
<style type="text/css">
li{
 font-size: 12px;
 color: #ffffff;
 background-image: url(images/bg1.gif);
 background-repeat: no-repeat;
 text-align: center;
 height: 33px;
 width:104px;
 line-height:38px;
 float:left;
 list-style:none;
 }
.out{
 background-image: url(images/bg1.gif);
 }
.over{
 background-image: url(images/bg2.gif);
 color:#ffff00;
 font-weight:bold;
 cursor:hand;
 }
</style>
</head>
<script type="text/javascript">
window.onload = function(){
 
 onscroll
 var li = document.getElementsByTagName("li");
 for(var i=0;i< li.length;i++){
   li[i].onmouseover = function(){
    this.className="over";
   }
   li[i].onmouseout = function(){
    this.className = "out";
   }
  }
 
 
}
 

</script>
<body>
<ul>
<li>资讯动态</li>
<li>产品世界</li>
<li>市场营销</li>
</ul>
  

</body>
</html>


0 0
原创粉丝点击