码迷,mamicode.com
首页 > Web开发 > 详细

JS实例之列表选中,实现类似好友列表选中效果

时间:2017-06-22 21:46:14      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:tle   utf-8   out   blog   logs   back   round   over   css   

 1 <head>
 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 3 <title>无标题文档</title>
 4 <style type="text/css">
 5 *{margin:0px auto; padding:0px;}
 6 #wai{width:100px; height:110px; margin-top:50px;}
 7 .list{width:100px; height:20px; background-color:#999; text-align:center; line-height:20px; vertical-align:middle; margin:2px; color:#FFF;}
 8 
 9 </style>
10 </head>
11 
12 <body>
13     <div id="wai">
14         <div class="list" onclick="dian(this)" onmouseover="show(this)" xz="0" onmouseout="huifu(this)"></div>
15         <div class="list" onclick="dian(this)" onmouseover="show(this)" xz="0" onmouseout="huifu(this)"></div>
16         <div class="list" onclick="dian(this)" onmouseover="show(this)" xz="0" onmouseout="huifu(this)"></div>
17         <div class="list" onclick="dian(this)" onmouseover="show(this)" xz="0" onmouseout="huifu(this)"></div>
18         <div class="list" onclick="dian(this)" onmouseover="show(this)" xz="0" onmouseout="huifu(this)"></div>
19     </div>
20 
21 </body>
22 <script type="text/javascript">
23 function dian(a){
24     var sy=document.getElementsByClassName("list");
25     for(i=0;i<sy.length;i++){
26         sy[i].style.backgroundColor ="#999";
27         sy[i].style.color ="#FFF";
28         sy[i].setAttribute("xz","0");
29     }
30     a.style.backgroundColor ="white";
31     a.style.color ="black";
32     a.setAttribute("xz","1");
33 }
34 function show(b){
35     var sy=document.getElementsByClassName("list");
36     for(i=0;i<sy.length;i++){
37         if(sy[i].getAttribute("xz")=="0"){
38             sy[i].style.backgroundColor ="#999";
39             sy[i].style.color ="#FFF";
40         }
41     }
42     b.style.backgroundColor ="white";
43     b.style.color ="black";
44 }
45 function huifu(){
46     var sy=document.getElementsByClassName("list");
47     for(i=0;i<sy.length;i++){
48         if(sy[i].getAttribute("xz")=="0"){
49             sy[i].style.backgroundColor ="#999";
50             sy[i].style.color ="#FFF";
51         }
52     }
53 }
54 </script>
55 </html>

技术分享

JS实例之列表选中,实现类似好友列表选中效果

标签:tle   utf-8   out   blog   logs   back   round   over   css   

原文地址:http://www.cnblogs.com/zym0m/p/7067067.html

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