jQuery Raty星级评分插件使用方法

转载自  jQuery Raty星级评分插件使用方法 

使用jQuery Raty,可以很方便的在页面上嵌入一个评分组件,如下所示:

1 2 3 4 5

使用方法很简单,首先从https://github.com/wbotelhos/raty下载raty的源代码(依赖于jquery)

然后在页面中引入相应的js文件、css文件、图片资源,在需要添加评分组件的元素上(比如span标签)添加下面的jquery代码即可:

$('span').raty();

以上为jQuery Raty的缺省使用方法,此外,该组件还支持丰富的传入参数和回调函数,例如:

设置jQuery Raty的初始评分:

2 2 3 4 5

评分回调函数

1 2 3 4 5

如果需要根据后台动态设置初始评分,可以使用回调函数实现。例如使用div中的data-attribute属性:

<div data-score="1"></div>

$('div').raty({score: function() {return $(this).attr('data-score');}
});

还可以改变星星的个数:

1 2 3 4 5 6 7 8 9 10

$('div').raty({ number: 10 });

只读模式:

1 2 3 4 5

$('div').raty({ readOnly: true, score: 3 });

点击事件:

1 2 3 4 5

$('div').raty({click: function(score, evt) {alert('ID: ' + this.id + "\nscore: " + score + "\nevent: " + evt);}
});

路径:

变更图标保存的位置,所有图标需要位于同一目录下,路径结尾的/不添加也可以

<div data-path="assets/images"></div>

$('div').raty({path: function() {return this.getAttribute('data-path');}
});

取消评分:

x 1 2 3 4 5

$('div').raty({ cancel: true });

全局改变设置:

你可以全局更改上述提到的所有设置 $.fn.raty.defaults.OPTION = VALUE;. 该语句必须添加在插件绑定之前。

$.fn.raty.defaults.path = assets;
$.fn.raty.defaults.cancel = true;

参数列表:

cancel      : false                                          // Creates a cancel button to cancel the rating.
cancelClass : 'raty-cancel'                                  // Name of cancel's class.
cancelHint  : 'Cancel this rating!'                          // The cancel's button hint.
cancelOff   : 'cancel-off.png'                               // Icon used on active cancel.
cancelOn    : 'cancel-on.png'                                // Icon used inactive cancel.
cancelPlace : 'left'                                         // Cancel's button position.
click       : undefined                                      // Callback executed on rating click.
half        : false                                          // Enables half star selection.
halfShow    : true                                           // Enables half star display.
hints       : ['bad', 'poor', 'regular', 'good', 'gorgeous'] // Hints used on each star.
iconRange   : undefined                                      // Object list with position and icon on and off to do a mixed icons.
mouseout    : undefined                                      // Callback executed on mouseout.
mouseover   : undefined                                      // Callback executed on mouseover.
noRatedMsg  : 'Not rated yet!'                               // Hint for no rated elements when it's readOnly.
number      : 5                                              // Number of stars that will be presented.
numberMax   : 20                                             // Max of star the option number can creates.
path        : undefined                                      // A global locate where the icon will be looked.
precision   : false                                          // Enables the selection of a precision score.
readOnly    : false                                          // Turns the rating read-only.
round       : { down: .25, full: .6, up: .76 }               // Included values attributes to do the score round math.
score       : undefined                                      // Initial rating.
scoreName   : 'score'                                        // Name of the hidden field that holds the score value.
single      : false                                          // Enables just a single star selection.
space       : true                                           // Puts space between the icons.
starHalf    : 'star-half.png'                                // The name of the half star image.
starOff     : 'star-off.png'                                 // Name of the star image off.
starOn      : 'star-on.png'                                  // Name of the star image on.
target      : undefined                                      // Element selector where the score will be displayed.
targetFormat: '{score}'                                      // Template to interpolate the score in.
targetKeep  : false                                          // If the last rating value will be keeped after mouseout.
targetScore : undefined                                      // Element selector where the score will be filled, instead of creating a new hidden field (scoreName option).
targetText  : ''                                             // Default text setted on target.
targetType  : 'hint'                                         // Option to choose if target will receive hint o 'score' type.
starType    : 'img'                                          // Element used to represent a star.

回调函数列表:

$('div').raty('score');                  // Get the current score.$('div').raty('score', number);          // Set the score.$('div').raty('click', number);          // Click on some star.$('div').raty('readOnly', boolean);      // Change the read-only state.$('div').raty('cancel', boolean);        // Cancel the rating. The last param force the click callback.$('div').raty('reload');                 // Reload the rating with the current configuration.$('div').raty('set', { option: value }); // Reset the rating with new configurations.$('div').raty('destroy');                // Destroy the bind and give you the raw element.$('div').raty('move', number);           // Move the mouse to the given score point position.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/326932.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

迷宫问题---递归解决

题目描述 代码实现 package com.atguigu.recursion;/*** 创建人 wdl* 创建时间 2021/3/21* 描述*/ public class MiGong {public static void main(String[] args) {//先创建一个二维数组&#xff0c;模拟迷宫//地图int[][] map new int[8][7];//使用1表示墙//上下全部置为1f…

20周年献礼:Visual Studio 2017正式版3月7日发布

微软透露 Visual Studio 2017 的开发工作已经接近尾声&#xff0c;即将进入 RTM 阶段。现在&#xff0c;微软正式宣布&#xff0c;Visual Studio 2017 正式版将于 3 月 7 日正式发布&#xff01;值得一提的是&#xff0c;今年正好是 Visual Studio 诞生 20 周年纪念。 为了表示…

JDK环境变量配置(一次性成功)

1.变量名&#xff1a; JAVA_HOME 变量值&#xff1a;&#xff08;变量值填写你的jdk的安装目录&#xff0c;例如本人是 E:\Java\jdk1.8.0&#xff09; 2.变量名&#xff1a; Path 变量值&#xff1a; ;%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin; 3.变量名&#xff1a; CLASSPATH …

Java 判断密码是否是大小写字母、数字、特殊字符中的至少三种

Java 判断密码是否是大小写字母、数字、特殊字符中的至少三种public class CheckPassword {//数字public static final String REG_NUMBER ".*\\d.*";//小写字母public static final String REG_UPPERCASE ".*[A-Z].*";//大写字母public static final St…

jquery插件star-rating.js实现星级评分特效

转载自 jquery插件star-rating.js实现星级评分特效 Bootstrap Star Rating是一个简单而强大的jQuery插件实现星级分数评级。支持像分数星填充和RTL输入先进的功能。在利用纯CSS-3造型使控制重点开发。该插件使用引导标记和造型默认情况下&#xff0c;但它可以覆盖与其他任何C…

C#winforms实现windows窗体人脸识别

在之前我写过一篇博客&#xff0c;是关于javaweb实现人脸识别&#xff0c;包括数据库以及java源码&#xff0c;还有相关的jar包都已经上传了&#xff0c;有想要了解的可以去看看&#xff0c;地址是&#xff1a;java实现人脸识别源码 实现了之后又正好朋友开发C#&#xff0c;想要…

八皇后问题判断此位置是否需合适

/**** param n 表示第n个皇后* return*/private boolean judge(int n){for (int i 0; i < n; i) {//说明//1.array[i]array[n]表示判断 第n个皇后是否和前面的n-1个皇后在同一列//2.Math.abs(n-i)Math.abs(array[n]-array[i])表示判断第n个皇后是否和第i皇后是否在同一斜线…

OSS.Common获取枚举字典列表标准库支持

上篇&#xff08;.Net Standard扩展支持实例分享&#xff09;介绍了OSS.Common的标准库支持扩展&#xff0c;也列举了可能遇到问题的解决方案。由于时间有限&#xff0c;同时.net standard暂时还没有提供对DescriptionAttribute的支持&#xff0c;所以其中的转化枚举到字典列表…

C#实现人脸识别【SqlHelper】

操作数据库工具类&#xff1a; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.Configuration; using…

八皇后问题---回溯

package com.atguigu.recursion;/*** 创建人 wdl* 创建时间 2021/3/21* 描述*/ public class Queue8 {//先定义一个max表示共有多少个皇后int max8;//定义数组array&#xff0c;保存皇后防止位置的结果&#xff0c;比如 arr[8] {0 , 4, 7, 5, 2, 6, 1, 3}int[] arraynew int[m…

程序员的情人节礼物:当天微软开始Build 2017登记

2016 年 12 月&#xff0c;微软曾经宣布 Build 2017 大会将于 2017 年 5 月 10 日至 12 日在美国西雅图举行&#xff1b;时隔两个月&#xff0c;关于 Build 2017 大会的消息&#xff0c;终于有了新的进展。 2 月 10 日&#xff0c;微软在官方博客中宣布 Build 2017 大会将开启注…

jQuery的三种bind/One/Live/On事件绑定使用方法

转载自 jQuery的三种bind/One/Live/On事件绑定使用方法 jQuery是 一款优秀的JavaScript框架,在旧版里主要用bind()方法&#xff0c;在新版里又多了两种One(),Live()&#xff0c;下面介绍这几种方法的使用 本篇文章介绍了&#xff0c;关于jQuery新的事件绑定机制on()的使用技…

C#实现人脸识别【Users】

这个类主要就是model类&#xff0c;对应数据库中的表users: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks;namespace Camtest {public class Users{//编号public long id { get; set; }//姓名public…

查找前端依赖 jquery css js 时间控件 不要用远程依赖 会变化的 card

BootCDN - Bootstrap 中文网开源项目免费 CDN 加速服务 找到你要的版本

使用VS Code从零开始开发调试.NET Core 1.1

使用VS Code 从零开始开发调试.NET Core 1.1。无需安装VS 2017 RC 即可开发调试.NET Core 1.1应用。 .NET Core 1.1 发布也有一段时间了&#xff0c;最大的改动是从 project.json 还原回了csproj 。 今天微软发布 .NET Core SDK 1.0 RC4 版本&#xff0c;离RTM版本也很近了。 对…

Linux 退出保存/不保存

先按ESC键 然后输入 :wq 保存并退出 :q! 不保存退出 你可以强制退出&#xff0c;或者先保存在退出 保存&#xff1a;w 强制退出 &#xff1a;q&#xff01; 无论是否退出 vi&#xff0c;均可保存所做的工作。按 ESC 键&#xff0c;确定 vi 是否处于命令模式。 操作 键入 保…

冒泡排序+推导过程

推导过程 代码实现 package com.atguigu.sort;import java.util.Arrays;/*** 创建人 wdl* 创建时间 2021/3/21* 描述*/ public class BubbleSort {public static void main(String[] args) {int arr[]{3,9,-1,10,-2};//为了容易理解&#xff0c;我们吧冒泡排序的演变过程给大家…

jQuery 基础教程 (五)之使用jQuery创建动画效果

一、jQuery 中的动画: 隐藏和显示 &#xff08;1&#xff09;hide() 在 HTML 文档中, 为一个元素调用 hide() 方法会将该元素的 display 样式改为 none. 代码功 能同 css(“display”, “none”); &#xff08;2&#xff09;show() 将元素的 display 样式改为先前的显示状 态…