[英]Turn JQuery Star Rating into Control
I have this fiddle , it's pretty cool, my first attempt at creating a jquery control. 我有这个小提琴 ,非常酷,这是我第一次尝试创建jquery控件。 It is simple, just a star ratings control. 很简单,只需一个星级评定控件即可。
I want to be able to turn this into a control, so that, I can call: 我希望能够将其转换为控件,以便可以调用:
$('#someDiv').starRating();
And it turns that div into a star rating. 它将div变成星级。
I would like to be able to then setup some properties: 我希望能够然后设置一些属性:
So it would look something like this: 所以看起来像这样:
$('#someDiv').starRating({
emptyStarSource : 'http://www.imageland.com/image.png',
hoverStarSource : 'http://www.imageland.com/image.png',
initialRating : 3
});
Similar to the Datepicker in how to change options etc. 与Datepicker相似,如何更改选项等。
If anyone could point me in the right direction that would be awesome! 如果有人能指出我正确的方向,那就太好了!
EDIT 编辑
So I have had a go with the help of the answer I got. 因此,我在得到的答案的帮助下进行了尝试。 The img click events aren't working, I'm guessing that somehow I have to attach the click handlers after I append them to the page. img click事件无法正常工作,我猜测将它们添加到页面后,我必须以某种方式附加单击处理程序。 how? 怎么样? After that, I just need to do the settings! 之后,我只需要进行设置即可!
To write a plugin in jQuery use the following syntax 要在jQuery中编写插件,请使用以下语法
$.fn.setRed = function(){
return $(this).each(function(){ //this is required for jQuery chaining to work and also if multiple html objects are passed
var _obj = $(this);
//work on the object here
_obj.css("background-color", "red");
});
}
You can then use 然后,您可以使用
$(".ratings").setRed();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.