jquery星级插件、支持页面中多次使用

所属分类: 网络编程 / JavaScript 阅读数: 1108
收藏 0 赞 0 分享
效果图如下:

css所需背景图片:

二话不说,帖代码:
html代码
复制代码 代码如下:

<div class="xing">
<span style="float: left">总体评价:<font color="#CC3300" size="-1">*</font></span><div
class="rating-wrap">
<ul id="xing1">
<li><a href="javascript:;" data-rate-value="10" data-hint="很差" title="很差" class="one-star">
</a></li>
<li><a href="javascript:;" data-rate-value="20" data-hint="差" title="差" class="two-stars ">
</a></li>
<li><a href="javascript:;" data-rate-value="30" data-hint="还行" title="还行" class="three-stars ">
</a></li>
<li><a href="javascript:;" data-rate-value="40" data-hint="好" title="好" class="four-stars">
</a></li>
<li><a href="javascript:;" data-rate-value="50" data-hint="很好" title="很好" class="five-stars">
</a></li>
</ul>
</div>
<span class="xing1">点击星星开始打分</span>
</div>
<divclass="xing">
<span style="float: left">广告效果:<font color="#CC3300"size="-1">*</font></span><div
class="rating-wrap">
<ulid="xing2">
<li><a href="javascript:;" data-rate-value="10" data-hint="很差" title="很差" class="one-star">
</a></li>
<li><a href="javascript:;" data-rate-value="20" data-hint="差" title="差" class="two-stars ">
</a></li>
<li><a href="javascript:;" data-rate-value="30" data-hint="还行" title="还行" class="three-stars ">
</a></li>
<li><a href="javascript:;" data-rate-value="40" data-hint="好" title="好" class="four-stars">
</a></li>
<li><a href="javascript:;" data-rate-value="50" data-hint="很好" title="很好" class="five-stars">
</a></li>
</ul>
</div>
<span class="xing2">点击星星开始打分</span>
</div>

JS代码
复制代码 代码如下:

<script type="text/javascript" src="js/jQuery_1.42.js"></script>
<script type="text/javascript">
$(function(){
$(".rating-wrap a").mouseover(function(){
$(this).parent().siblings().find("a").removeClass("active-star");
$(this).addClass("active-star");
$("."+$(this).parent().parent().attr("id")).html($(this).attr("data-hint"))
}).mouseleave(function(){
var selectID=$(this).parent().parent().attr("id")+"select";
$(this).removeClass("active-star");
if($("#"+selectID).length==0)
{
$("."+$(this).parent().parent().attr("id")).removeClass("active-hint").html("点击星星开始打分");
}
else
{
$("."+$(this).parent().parent().attr("id")).html($("#"+selectID).attr("data-hint"));
$("#"+selectID).addClass("active-star");
}
}).click(function(){
$(this).addClass("active-star").attr('id',$(this).parent().parent().attr("id")+"select");
$(this).parent().siblings().find("a").attr("id","");
$("."+$(this).parent().parent().attr("id")).html($(this).attr("data-hint")).addClass("active-hint");
})
})
</script>

css代码
复制代码 代码如下:

<style>
.item-rank-rst, .user-rank-rst, .rating-wrap ul, .rating-wrap a:hover, .rating-wrap .active-star, .user-m-star, .urr-rank60, .breadcrumb .note {
background-image: url(xing_bg.png);/**-----星级插件背景图片----**/
background-repeat: no-repeat;
}
.rating-wrap {
background: none repeat scroll 0 0 #FFF9F1;
border: 1px solid #EFE0D7;
display: inline-block;
float: left;
height: 20px;
margin-right: 5px;
padding: 4px 0 0 5px;
position: relative;
top: -2px;
width: 89px;
z-index: 0;
}
.rating-wrap ul {
background-position: 0 -250px;
height: 16px;
position: relative;
width: 85px;
z-index: 10;
}
.rating-wrap li {
display: inline;
}
.rating-wrap a {
display: block;
height: 16px;
left: 0;
position: absolute;
top: 0;
}
.rating-wrap .five-stars {
background-position: 0 -160px;
width: 84px;
z-index: 10;
}
.rating-wrap .four-stars {
background-position: 0 -178px;
width: 68px;
z-index: 20;
}
.rating-wrap .three-stars {
background-position: 0 -196px;
width: 51px;
z-index: 30;
}
.rating-wrap .two-stars {
background-position: 0 -214px;
width: 34px;
z-index: 40;
}
.rating-wrap .one-star {
background-position: 0 -232px;
width: 17px;
z-index: 50;
}
.rating-block .hint {
color: #999999;
float: left;
}
.active-hint {
color: #CC0000;
}
.rating-block .err-hint {
color: #EE0000;
font-weight: bold;
}
</style>

注:css代码从项目中分解出,有一小部分没贴完,大家可以根据自己的需求修改css style
更多精彩内容其他人还在看

Vue组件选项props实例详解

父组件通过 props 向下传递数据给子组件,子组件通过 events 给父组件发送消息。本文将详细介绍Vue组件选项props,需要的朋友可以参考下
收藏 0 赞 0 分享

javascript将url解析为json格式的两种方法

本篇文章主要介绍了javascript将url解析为json格式的两种方法,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
收藏 0 赞 0 分享

详解JS数组Reduce()方法详解及高级技巧

reduce 为数组中的每一个元素依次执行回调函数,不包括数组中被删除或从未被赋值的元素。接下来通过本文给大家分享JS数组Reduce()方法详解及高级技巧,一起看看吧
收藏 0 赞 0 分享

JS模拟超市简易收银台小程序代码解析

本文通过实例代码给大家介绍了JS模拟超市简易收银台小程序代码,非常不错,具有参考借鉴价值,需要的的朋友参考下吧
收藏 0 赞 0 分享

JavaScript 完成注册页面表单校验的实例

下面小编就为大家带来一篇JavaScript 完成注册页面表单校验的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

简单的网页广告特效实例

下面小编就为大家带来一篇简单的网页广告特效实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue内容分发slot(全面解析)

下面小编就为大家带来一篇Vue内容分发slot(全面解析)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Vue自定义事件(详解)

下面小编就为大家带来一篇Vue自定义事件(详解)。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

Mui使用jquery并且使用点击跳转新窗口的实例

下面小编就为大家带来一篇Mui使用jquery并且使用点击跳转新窗口的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享

深入理解ES6的迭代器与生成器

本篇文章主要介绍了深入理解ES6的迭代器与生成器,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
收藏 0 赞 0 分享
查看更多