js 淘宝评分

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>无标题文档</title>
        <script>
            window.onload = function (){
                var oUl = document.getElementById("list");
                var aLi = oUl.getElementsByTagName("li");
                var half = 2;
                var off = 1;

                for(var i = 0; i < aLi.length; i++)
                {
                    aLi[i].index = i;
                    aLi[i].onmouseover = function (){
                        if(off)
                        {
                            fillstar(this.index,half);
                        }
                        
                        
                    
                    }

                    aLi[i].onmouseout = function (){

                        if(off)
                        {
                            for(var i = 0; i < aLi.length; i++ )
                            {
                            aLi[i].style.background = "url(http://img.alicdn.com/tps/i1/T1r.UsXf4dXXcC1lsa-204-400.png) no-repeat";
                            }
                        }

                        
                    }

                    aLi[i].onclick = function (){
                        if(off)
                        {
                            fillstar(this.index,half);    
                            off = !off;
                        }
                        
                    }

                    function fillstar(num,half){

                        if( num < half )
                        {
                            for(var i = 0; i <= num; i++)
                            {
                                aLi[i].style.background = "url(http://img.alicdn.com/tps/i1/T1r.UsXf4dXXcC1lsa-204-400.png) no-repeat 0px -116px";
                            }
                            

                        }else if ( num >= half && num < aLi.length - 1 ){
                            
                            for(var i = 0; i <= num; i++)
                            {
                                aLi[i].style.background = "url(http://img.alicdn.com/tps/i1/T1r.UsXf4dXXcC1lsa-204-400.png) no-repeat 0px -57px";
                            }
                        }else {

                            for(var i = 0; i <= num; i++)
                            {
                                aLi[i].style.background = "url(http://img.alicdn.com/tps/i1/T1r.UsXf4dXXcC1lsa-204-400.png) no-repeat 0px -87px";
                            }
                        }
                    }
                }



                

            }
        </script>
        <style>
            #list{list-style: none;}
            #list li{
                height: 23px;
                width: 24px;
                background: url(http://img.alicdn.com/tps/i1/T1r.UsXf4dXXcC1lsa-204-400.png) no-repeat;
                display: block;
                float: left;
                cursor: pointer;

            }
        </style>
    </head>
    <body>
        <ul id = "list">
            <li></li>
            <li></li>
            <li></li>
            <li></li>
            <li></li>
        </ul>
    </body>
</head>

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。