基于jQuery实现的美观星级评论打分组件代码
2019/6/29 21:52:48
本文主要是介绍基于jQuery实现的美观星级评论打分组件代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
本文实例讲述了基于jQuery实现的美观星级评论打分组件代码。分享给大家供大家参考,具体如下:
这款jquery星级评论打分组件,是通用打分组件,callBack打分后执行的回调,this.Index:获取当前选中值。
运行效果截图如下:
在线演示地址如下:
http://demo.zyiz.net/js/2015/jquery-rate-dfzj-codes/
具体代码如下:
<!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>jquery星级评论打分组件</title> <script src="jquery-1.6.2.min.js"></script> <script> var pRate = function(box,callBack){ this.Index = null; var B = $("#"+box), rate = B.children("i"), w = rate.width(), n = rate.length, me = this; for(var i=0;i<n;i++){ rate.eq(i).css({ 'width':w*(i+1), 'z-index':n-i }); } rate.hover(function(){ var S = B.children("i.select"); $(this).addClass("hover").siblings().removeClass("hover"); if($(this).index()>S.index()){ S.addClass("hover"); } },function(){ rate.removeClass("hover"); }) rate.click(function(){ rate.removeClass("select hover"); $(this).addClass("select"); me.Index = $(this).index() + 1; if(callBack){callBack();} }) } </script> <style type="text/css"> h1{font:26px/3 'microsoft yahei','simhei';color:#000;text-indent:2em;text-shadow:1px 1px 2px #ccc} .p_rate{height:14px;position:relative;width:80px;overflow:hidden;display:inline-block;background:url(images/rate.png) repeat-x;margin:40px 100px} .p_rate i{position:absolute;top:0;left:0;cursor:pointer;height:14px;width:16px;background:url(images/rate.png) repeat-x 0 -500px} .p_rate .select{background-position:0 -32px} .p_rate .hover{background-position:0 -16px} </style> </head> <body> <h1>jquery星级评论打分组件</h1> <span class="p_rate" id="p_rate"> <i title="1分"></i> <i title="2分"></i> <i title="3分"></i> <i title="4分"></i> <i title="5分"></i> </span> <script> var Rate = new pRate("p_rate",function(){ alert(Rate.Index+'分') }); </script> </body> </html>
希望本文所述对大家jQuery程序设计有所帮助。
这篇关于基于jQuery实现的美观星级评论打分组件代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-03-06jquery对css样式(jquery中的css方法)-icode9专业技术文章分享
- 2023-05-27JQuery的认识和安装
- 2023-01-06JQuery应用技巧:如何定义 HTML 模板并使用 JQuery 进行加载-icode9专业技术文章分享
- 2022-09-29复习-jQuery
- 2022-09-04Python3项目初始化10-->前端基础jquery、ajax,sweetalert--更新用户改造
- 2022-08-30day 27 jquery
- 2022-08-29jQuery筛选器,bootstrap
- 2022-08-20JQuery事件绑定
- 2022-08-20JQuery案例
- 2022-08-07关于jQuery的学习