原生JS星级评分

来源:互联网 发布:pose studio软件下载 编辑:程序博客网 时间:2024/05/09 08:26
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>五星评价</title>
<style>
a{ display:inline-block; height:30px; width:30px; padding:5px;background:url(star.png) no-repeat center -40px}
.ac{ background-position:center 0}


</style>
</head>


<body>
<a></a><a></a><a></a><a></a><a></a>
</body>
</html>
<script type="text/javascript">
var A=document.getElementsByTagName('a');
var n;
for (var i = 0; i < A.length; i++) {
A[i].index=i;
A[i].onmouseover=function(){
star(this.index);
// for(var j=0;j<A.length;j++){
// if (j<=this.index) {
// A[j].className='ac';
// }else{
// A[j].className='';
// }


// }
}
A[i].onmouseout=function(){
star(n);
// alert(n);
// for (var j = 0; j < A.length; j++) {
// if(j<=n){
// A[j].className='ac';
// }else{
// A[j].className='';
// }
// }
}
A[i].onclick=function(){
n=this.index;
}


}
function star(t){
for (var j = 0; j < A.length; j++) {
if(j<=t){
A[j].className='ac';
}else{
A[j].className='';
}
}
}
</script>
原创粉丝点击