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


Posted in Javascript onMarch 25, 2012

效果图如下:

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

css所需背景图片:
jquery星级插件、支持页面中多次使用
二话不说,帖代码:
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
Javascript 相关文章推荐
用javascript编写的第一人称射击游戏
Feb 25 Javascript
use jscript List Installed Software
Jun 11 Javascript
JavaScript 数组的 uniq 方法
Jan 23 Javascript
Jquery实现视频播放页面的关灯开灯效果
May 27 Javascript
js复制到剪切板的实例方法
Jun 28 Javascript
jQuery中wrapAll()方法用法实例
Jan 16 Javascript
JavaScript常用字符串与数组扩展函数小结
Apr 24 Javascript
JS实现表单多文件上传样式美化支持选中文件后删除相关项
Sep 30 Javascript
详解JavaScript 中getElementsByName在IE中的注意事项
Feb 21 Javascript
Node.JS段点续传:Nginx配置文件分段下载功能的实现方法
Mar 12 Javascript
原生JavaScript实现日历功能代码实例(无引用Jq)
Sep 23 Javascript
javascript实现倒计时提示框
Mar 02 Javascript
JQuery实现倒计时按钮的实现代码
Mar 23 #Javascript
JQuery防止退格键网页后退的实现代码
Mar 23 #Javascript
jQuery中将函数赋值给变量的调用方法
Mar 23 #Javascript
ExtJs使用总结(非常详细)
Mar 22 #Javascript
常用Extjs工具:Extjs.util.Format使用方法
Mar 22 #Javascript
Extjs中ComboBox加载并赋初值的实现方法
Mar 22 #Javascript
利用json获取字符出现次数的代码
Mar 22 #Javascript
You might like
理解PHP5中static和const关键字的区别
2007/03/19 PHP
php win下Socket方式发邮件类
2009/08/21 PHP
PHP基于GD库的缩略图生成代码(支持jpg,gif,png格式)
2014/06/19 PHP
php中字符串和正则表达式详解
2014/10/23 PHP
Yii2中hasOne、hasMany及多对多关联查询的用法详解
2017/02/15 PHP
php中文乱码问题的终极解决方案汇总
2017/08/01 PHP
ExtJS4 Grid改变单元格背景颜色及Column render学习
2013/02/06 Javascript
js多级树形弹出一个小窗口层(非常好用)实例代码
2013/03/19 Javascript
JQueryEasyUI datagrid框架的进阶使用
2013/04/08 Javascript
jQuery中append()方法用法实例
2015/01/08 Javascript
浅谈Node.js中的定时器
2015/06/18 Javascript
原生js实现可拖拽效果
2017/02/28 Javascript
Javascript实现的StopWatch功能示例
2017/06/13 Javascript
微信小程序 转发功能的实现
2017/08/04 Javascript
Vue下拉框回显并默认选中随机问题
2018/09/06 Javascript
Egg.js 中 AJax 上传文件获取参数的方法
2018/10/10 Javascript
js+html5 canvas实现ps钢笔抠图
2019/04/28 Javascript
vue 实现微信浮标效果
2019/09/01 Javascript
详解JavaScript自定义函数
2020/07/29 Javascript
在vue中使用eslint,配合vscode的操作
2020/11/09 Javascript
[01:41]DOTA2 2015国际邀请赛中国区预选赛第三日战报
2015/05/28 DOTA
Python中optparse模块使用浅析
2015/01/01 Python
浅谈python之高阶函数和匿名函数
2019/03/21 Python
Python编写打字训练小程序
2019/09/26 Python
Windows下PyCharm2018.3.2 安装教程(图文详解)
2019/10/24 Python
详解centos7+django+python3+mysql+阿里云部署项目全流程
2019/11/15 Python
移动端html5模拟长按事件的实现方法
2018/09/30 HTML / CSS
德国最大的网上鞋店之一:Schuhe24.de
2017/06/10 全球购物
荷兰时尚精品店:Labels Fashion
2020/03/22 全球购物
医学检验专业大学生求职信
2013/11/18 职场文书
就业协议书怎么填
2014/04/11 职场文书
大学生优秀班干部事迹材料
2014/05/26 职场文书
分公司经理任命书
2014/06/05 职场文书
2014年小学教导处工作总结
2014/12/19 职场文书
Mysql官方性能测试工具mysqlslap的使用简介
2021/05/21 MySQL
Linux7.6二进制安装Mysql8.0.27详细操作步骤
2021/11/27 MySQL