明霞山资源网 Design By www.htccd.com
本文实例为大家分享了JavaScript实现商品评价五星好评的具体代码,供大家参考,具体内容如下
一.效果展示
二.代码实现
1.html代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>好评</title>
<link rel="stylesheet" type="text/css" href="../js7/css/reset.css" />
<link rel="stylesheet" type="text/css" href="css/myTest3.css" />
<script type="text/javascript">
window.onload = function(){
ul = document.getElementById('star');
lis = ul.getElementsByTagName('li');
for (var i = 0; i < lis.length; i++) {
lis[i].onclick = function(){
//被用户点击后弹框并提示分数
//获取当前对象的对象名
var className = this.className;//nostart
//重新定义class,并弹出评分
ul.className = "nostar " + className;
var score = this.getElementsByTagName('a')[0].title;
console.log(score);
alert('评分:' + score);
}
}
}
</script>
</head>
<body>
<ul class="nostar " id="star">
<li class="onestar"><a title="1分"></a></li>
<li class="twostar"><a title="2分"></a></li>
<li class="threestar"><a title="3分"></a></li>
<li class="fourstar"><a title="4分"></a></li>
<li class="fivestar"><a title="5分"></a></li>
</ul>
</body>
</html>
2.css代码
body{
padding: 200px 600px;
}
.nostar{
width: 80px;
height: 16px;
background: url(../img/star-matrix.gif) no-repeat;
position: relative;
}
.nostar li {
width: 16px;
height: 16px;
float: left;
}
.nostar li a{
display: inline-block;
width: 16px;
height: 16px;
position: absolute;
/* text-indent: -999px; */
/* 层级关系*/
z-index: 10;
}
.nostar li a:hover{
/* 将a的大小变化 width 80 */
left: 0px;
width: 80px;
background: url(../img/star-matrix.gif) no-repeat;
z-index: 5;
}
.onestar{background-position: 0 -16px;}
.twostar{background-position: 0 -32px;}
.threestar{background-position: 0 -48px;}
.fourstar{background-position: 0 -64px;}
.fivestar{background-position: 0 -80px;}
.nostar li.onestar a:hover{ background-position: 0 -96px ;}
.nostar li.twostar a:hover{ background-position: 0 -112px ;}
.nostar li.threestar a:hover{ background-position: 0 -128px ;}
.nostar li.fourstar a:hover{ background-position: 0 -144px ;}
.nostar li.fivestar a:hover{ background-position: 0 -160px ;}
3.代码下载
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
明霞山资源网 Design By www.htccd.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
明霞山资源网 Design By www.htccd.com
暂无评论...
RTX 5090要首发 性能要翻倍!三星展示GDDR7显存
三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。
首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。
据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。
