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 相关文章推荐
解决FireFox下[使用event很麻烦]的问题
Nov 26 Javascript
Uglifyjs(JS代码优化工具)入门 安装使用
Apr 13 Javascript
seajs1.3.0源码解析之module依赖有序加载
Nov 07 Javascript
JavaScript数组Array对象增加和删除元素方法总结
Jan 20 Javascript
window.onload与$(document).ready()的区别分析
May 30 Javascript
BootStrap智能表单实战系列(七)验证的支持
Jun 13 Javascript
angular.js指令中的controller、compile与link函数的不同之处
May 10 Javascript
vue 全选与反选的实现方法(无Bug 新手看过来)
Feb 09 Javascript
Vue+webpack+Element 兼容问题总结(小结)
Aug 16 Javascript
angular2 ng2-file-upload上传示例代码
Aug 23 Javascript
详解小程序rich-text对富文本支持方案
Nov 28 Javascript
node.js实现上传文件功能
Jul 15 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
PHP中调用SVN命令更新网站方法
2015/01/07 PHP
PHP 生成微信红包代码简单
2016/03/25 PHP
JavaScript window.setTimeout() 的详细用法
2009/11/04 Javascript
腾讯与新浪的通过IP地址获取当前地理位置(省份)的接口
2010/07/26 Javascript
利用javascript打开模态对话框(示例代码)
2014/01/11 Javascript
javascript如何写热点图
2015/12/08 Javascript
AngularJS使用指令增强标准表单元素功能
2016/07/01 Javascript
详解Puppeteer前端自动化测试实践
2019/02/21 Javascript
微信小程序开发常见问题及解决方案
2019/07/11 Javascript
微信小程序如何获取群聊的openGid以及名称详解
2019/07/17 Javascript
[06:53]DOTA2每周TOP10 精彩击杀集锦vol.3
2014/06/25 DOTA
[00:02]DOTA2新版本使用PA至宝后暴击展示
2014/11/19 DOTA
[25:45]2018DOTA2亚洲邀请赛4.5SOLO赛 Sylar vs Paparazi
2018/04/06 DOTA
[58:23]LGD vs TNC 2019国际邀请赛小组赛 BO2 第一场 8.15
2019/08/16 DOTA
python实现文件分组复制到不同目录的例子
2014/06/04 Python
深入理解NumPy简明教程---数组2
2016/12/17 Python
python3操作mysql数据库的方法
2017/06/23 Python
python复制文件到指定目录的实例
2018/04/27 Python
Sanic框架请求与响应实例分析
2018/07/16 Python
python实现趣味图片字符化
2019/04/30 Python
Django上线部署之IIS的配置方法
2019/08/22 Python
python打印n位数“水仙花数”(实例代码)
2019/12/25 Python
Python Scrapy框架:通用爬虫之CrawlSpider用法简单示例
2020/04/11 Python
jupyter notebook 重装教程
2020/04/16 Python
Hotels.com台湾:饭店订房网
2017/09/06 全球购物
Sephora丝芙兰泰国官方网站:国际知名化妆品购物
2017/11/15 全球购物
工艺工程师工作职责
2013/11/23 职场文书
违反交通安全法检讨书
2014/10/24 职场文书
2014年大学生村官工作总结
2014/11/19 职场文书
故意杀人罪辩护词
2015/05/21 职场文书
同意报考公务员证明
2015/06/17 职场文书
期中考试后的感想
2015/08/07 职场文书
如何用Laravel包含你自己的帮助函数
2021/05/27 PHP
详解Python类和对象内容
2021/06/22 Python
深入理解go slice结构
2021/09/15 Golang
Nginx虚拟主机的搭建的实现步骤
2022/01/18 Servers