zoukankan      html  css  js  c++  java
  • js星星打分效果详解

    很多网站都有如下图这样的星星打分效果,今天就看下用js怎么实现打分效果。

    效果详解

    1. 鼠标移上的时候星星点亮,下面的文字显示。鼠标移出的时候星星为灰,下面文字不显示。

    2. 鼠标移到某个星星上,它之前的所有星星都会亮。

    3. 鼠标移到某个星星上并点击,会显示打分结果。

    代码如下

    <!doctype html>
    <html>
    <head>
    <meta charset="gbk">
    <title>切换</title>
    <style>
    .wrapper
    {width:300px; margin:10px auto; font:14px/1.5 arial;}
    /*tab*/
    #star
    {overflow:hidden;}
    #star li
    {float:left; width:20px; height:20px; margin:2px; display:inline; color:#999; font:bold 18px arial; cursor:pointer}
    #star .act
    {color:#c00}
    #star_word
    {width:80px; height:30px; line-height:30px; border:1px solid #ccc; margin:10px; text-align:center; display:none}

    </style>
    <script>
    window.onload
    = function(){

    var star = document.getElementById("star");
    var star_li = star.getElementsByTagName("li");
    var star_word = document.getElementById("star_word");
    var result = document.getElementById("result");
    var i=0;
    var j=0;
    var len = star_li.length;
    var word = ['很差','','一般',"","很好"]

    for(i=0; i<len; i++){
    star_li[i].index
    = i;

    star_li[i].onmouseover
    = function(){
    star_word.style.display
    = "block";
    star_word.innerHTML
    = word[this.index];
    for(i=0; i<=this.index; i++){
    star_li[i].className
    = "act";

    }
    }

    star_li[i].onmouseout
    = function(){
    star_word.style.display
    = "none";
    for(i=0; i<len; i++){
    star_li[i].className
    = "";
    }
    }

    star_li[i].onclick
    = function(){
    result.innerHTML
    = (this.index+1)+"";
    }


    }

    }
    </script>
    </head>
    <body>
    <div class="wrapper">
    打分结果
    <span id="result"></span>
    <ul id="star">
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    <li></li>
    </ul>
    <div id="star_word">一般</div>

    </div>


    </body>
    </html>



    我的微博 http://weibo.com/u/1650528354
    博客地址 http://www.cnblogs.com/jingangel/
    本博的代码都是博主边学习边写的,代码都是自己敲的,如果要复制请加上出处,谢谢!
  • 相关阅读:
    数据取证任务
    VMware虚拟机重置密码
    pon(无源光纤网络)
    Gpon与Epon的区别
    DNS相关
    牛人博客收集
    值得细细品读的URL资源
    SQL注入
    IPSec方案部署(多业务场景)
    python专题-函数式编程
  • 原文地址:https://www.cnblogs.com/jingangel/p/2360731.html
Copyright © 2011-2022 走看看