zoukankan      html  css  js  c++  java
  • 原生javascript星级评分

    写个最简单的原生js的星级评分:

    Html代码  
    1. <div id="rank" class="pingfen">  
    2.     <ul>  
    3.         <li></li>  
    4.         <li></li>  
    5.         <li></li>  
    6.         <li></li>  
    7.         <li></li>  
    8.     </ul>  
    9.     <p>加载中</p>  
    10. </div>  

     

    Css代码  
    1. <style type="text/css">  
    2.     *{margin: 0;padding: 0;}  
    3. .pingfen{  135px; margin:10px auto; height:20px; position: relative;}  
    4. .pingfen ul{height:20px; margin-bottom: 10px;}  
    5. .pingfen li{  20px; float: left; height: 20px; cursor: pointer; background: url(star.png) no-repeat 0 0; list-style: none;}  
    6. .pingfen .active{background: url(star.png) no-repeat 0 -28px;}  
    7. .pingfen p{ position: absolute; top:24px; left: 0px;  134px; height: 28px; background: #fff; line-height: 28px; text-align: center; border:1px solid #333; display:none;}  
    8. </style>  

     

    Js代码  
    1. <script>  
    2. var aData =["很差","较差","一般","推荐","力推"];  
    3.   
    4. window.onload=function(){  
    5.     var oDiv = document.getElementById("rank");  
    6.     var aLi = oDiv.getElementsByTagName("li");  
    7.     var oP = oDiv.getElementsByTagName("p")[0];  
    8.     var i =0;  
    9.     for(i=0;i<aLi.length;i++){  
    10.         aLi[i].index = i;  
    11.             aLi[i].onmouseover = function(){  
    12.             oP.style.display = "block";  
    13.             oP.innerHTML=aData[this.index];  
    14.             for(i=0; i<=this.index;i++){  
    15.                 aLi[i].className="active";  
    16.             }  
    17.         };  
    18.         aLi[i].onmouseout = function(){  
    19.             oP.style.display = "";  
    20.             for(i=0; i<aLi.length; i++){  
    21.                 aLi[i].className="";  
    22.             }  
    23.         };  
    24.         aLi[i].onclick=function(){  
    25.             alert(this.index +1);  
    26.         };  
    27.     }  
    28.   
    29. };  
    30. </script>  

     

     

    ok超级简单不信你试试。

  • 相关阅读:
    ImportError: libgthread-2.0.so.0: cannot open shared object file: No such file or directory
    pycocotools使用教程
    with torch.no_grad() 详解
    虚拟机Ubuntu上下载Pytorch显示超时
    Deep Layer Aggregation DLA网络的结构
    tgz文件解压命令
    install mysql at linux
    devops issue
    process data
    unittest
  • 原文地址:https://www.cnblogs.com/xiaochao12345/p/3621187.html
Copyright © 2011-2022 走看看