例子:好友列表选中效果

<style type="text/css">

*{ margin:0px auto; padding:0px; font-family:微软雅黑; font-size:16px;}

.f{ width:200px; height:30px; background-color:#63C; color:white; text-align:center; line-height:30px; vertical-align:middle; margin-top:3px}

.f:hover{ cursor:pointer;}

</style>

 

<div style="width:200px; height:600px; margin-top:30px">      

<div class="f" οnclick="Xuan(this)" οnmοuseοver="Bian(this)" οnmοuseοut="Hui(this)" xz="0">张三</div>    

<div class="f" οnclick="Xuan(this)" οnmοuseοver="Bian(this)" οnmοuseοut="Hui(this)" xz="0">李四</div>    

<div class="f" οnclick="Xuan(this)" οnmοuseοver="Bian(this)" οnmοuseοut="Hui(this)" xz="0">王五</div>    

<div class="f" οnclick="Xuan(this)" οnmοuseοver="Bian(this)" οnmοuseοut="Hui(this)" xz="0">赵六</div>    

<div class="f" οnclick="Xuan(this)" οnmοuseοver="Bian(this)" οnmοuseοut="Hui(this)" xz="0">马七</div>    

</div>

 

<script type="text/javascript">
 
 function Xuan(a)
 {
  var attr = document.getElementsByClassName("f");
  
  for(var i=0;i<attr.length;i++)
  {
   attr[i].style.backgroundColor = "#63C";
   attr[i].setAttribute("xz","0");
  }
  a.setAttribute("xz","1");
  a.style.backgroundColor = "#F63";
 }
 
 function Bian(a)
 {
  var attr = document.getElementsByClassName("f");
  
  for(var i=0;i<attr.length;i++)
  {
   if(attr[i].getAttribute("xz")=="0")
   {
    attr[i].style.backgroundColor = "#63C";
   }
  }
  
  a.style.backgroundColor = "#F63";
 }
 
 
 function Hui(a)
 {
  var attr = document.getElementsByClassName("f");
  
  for(var i=0;i<attr.length;i++)
  {
   if(attr[i].getAttribute("xz")=="0")
   {
    attr[i].style.backgroundColor = "#63C";
   }
  }
 }
 
</script>

转载于:https://www.cnblogs.com/l5580/p/5909277.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值