js+html的超简单星型评分

以前在做server页面时有做到一个星级评分的页面效果,虽然不不算好看,但也记下来吧。

通过选择框中的值控制黄色星的多少,原理就是控制css显示宽度来达到视觉效果

code:

<!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>make score page</title>
<style>
 .fivestars,.fivestars div{background:transparent url(../mkscore/commstar.gif) repeat-x scroll left bottom;width:130px;}
.fivestars{padding:0; position:relative; line-height:28px;display:inline-block;}
.fivestars div{background-position:bottom center; text-indent:-9999px;}
.fivestars div{background-position:left top; width:0px;}
</style>
<script type="text/javascript">
function changestars(score)
{
 
 var w=26; /* one star's width */
 var totalw=w*score; /* score stars */
 var aa=document.getElementById("autostars");
 aa.style.width=totalw+"px";

</script>
</head>

<body>
<select οnchange="changestars(this.value)">
  <option value="" selected="selected">--请选择--</option>
  <option value="0">0分</option>
  <option value="0.5">0.5分</option>
  <option value="1">1分</option>
  <option value="1.5">1.5分</option>
  <option value="2">2分</option>
  <option value="2.5">2.5分</option>
  <option value="3">3分</option>
  <option value="3.5">3.5分</option>
  <option value="4">4分</option>
  <option value="4.5">4.5分</option>
  <option value="5">5分</option>
</select>
<div class="fivestars" id="fivestars"><div class="autostars" id="autostars">&nbsp;</div></div>
</body>
</html>

这里之所以是通过下拉选择框来选择星星评分,是因为这个系统是提供给androidTV用的,而在android2.2,2.3上不支持js的一些网页效果,本来是做成用鼠标直接点击星星来评分的,后来改了,后来发现在android4.0上又可以支持了,但也没改了,其实那样也简单,就是用css打开div的可点击状态,就是当鼠标移动到div上时,div会变成手状,然后通过js捕捉鼠标点击事件,然后改变其显示宽度就ok了,具体代码就不记了。
  • 5
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值