Day4-----score

//--------------------------使用遍历完成星星的评分,使用innerHTML完成评价

<html>
<head><title>score</title></head>
<style type="text/css">
    body{font-size: 20px;font-weight: bold;}
    img{width: 30px;height: 30px;}
    li{list-style-type: none;float: left;}
    #text{width: 100px;height: 30px;border: 1px solid #CCC;float: left;text-align: center;}
</style>
<script type="text/javascript">
    window.onload=function(){
        var i;
        var timer;
        var text=["terrible","bad","normal","good","great"];
        oImg=document.getElementsByTagName('img');
        oDiv=document.getElementById('text');
        for(i=0;i<oImg.length;i++){
            oImg[i].src="pic/gray.png";    
            oImg[i].index=i;        
            oImg[i].onmouseover=function(){    
                for(i=0;i<oImg.length;i++) oImg[i].src="pic/gray.png";    
                for(i=0;i<(this.index+1);i++)    oImg[i].src="pic/gold.png";
                oDiv.innerHTML=text[this.index];
            }
            oImg[i].onclick=function(){
                for(i=0;i<(this.index+1);i++) oImg[i].src="pic/gold.png";
            }
        } 
        
    }
</script>
<body>
    <ul>
        <li><img /></li>
        <li><img /></li>
        <li><img /></li>
        <li><img /></li>
        <li><img /></li>
        <div id="text">Score</div>
    </ul>
</body>
</html>

 

posted on 2014-11-23 12:45  fleshy  阅读(139)  评论(0编辑  收藏  举报

导航