日期:2014-05-16 浏览次数:20445 次
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
<style type="text/css">
.starBox{position: relative;padding:0;height:30px;background:url(star.gif) left top repeat-x}
.defaultStars{ height:30px; background:url(star.gif) left -60px repeat-x; }
.starBox a{
position:absolute; left:0; top:0;
height:30px;text-indent:-1000px; overflow:hidden;
background:url(star.gif) left 100px repeat-x;
outline:none;hide-focus:expression(this.hideFocus=true);
}
.starBox a:hover{ background-position:left -30px}
</style>
<script type="text/javascript">
function $(id){return document.getElementById(id);}
window.onload = function(){
//参数1,字符串,为想要显示星星打分的外层容器id,不需要什么样式规范等
//参数2,字符串数组,为星星鼠标放上去的提示文本(title),数组的长度也就是星星的数量
//参数3,整数,默认级别,其实这里稍微改动一下,就可以变成显示已打分的平均分
rate("音色",["很差","不好","一般","还可以","很好"],1);
rate("手感",["很差","不好","一般","还可以","很好"],1);
rate("外观",["很差","不好","一般","还可以","很好"],1);
rate("售后",["很差","不好","一般","还可以","很好"],1);
}
function rate(divID,titles,defaultValue){
var size = titles.length;
var rateHTML = "<div class='starBox' style='width:" + 30*size + "px'>";
//默认级别层defaultStars,宽度为设置的级别 × 1个星星的宽度
rateHTML += "<div class='defaultStars' style='width:" + 30*defaultValue + "px'></div>";
for (var i=1;i<=size;i++){
var index = size-i; //z-index,递减
rateHTML += "<a href='javascript:void(0)' style='width:" + 30*i + "px;z-index:" + index +"' title='" + titles[i-1] + "'>" + i + "</a>";
}
rateHTML += "</div>";
$(divID).innerHTML = rateHTML;
//星星点击事件
$(divID).onclick = function(e){
var src = e?e.target:event.srcElement;
if (src.tagName == "A"){
//移除默认级别的层,只是绝对点击之后不需要他了,也不好看
src.parentNode.firstChild.style.display="none";
src.style.backgroundPosition = "left -30px";
//创建一个空的层,覆盖所有星星,让他们不在对鼠标做出反映
var mask = document.createElement("div");
mask.style.cssText = "width:100%;height:100%;position:absolute; left:0; top:0;z-index:99";
src.parentNode.appendChild(mask);
var zs=src.innerHTML
//提交到数据库
//返回信息
alert(divID+"你选择的是:" +zs);
}
}
}
</script>
</head>
<body>
<p>音色</p>
<span id="音色"></span>
<p>手感</p>
<span id="手感"></span>
<p>外观</p>
<span id="外观"></span>
<p>售后</p>
<span id="售后"></span>
</body>
</html>