丶明灯三千
2019-02-14 22:37
<script> var rating = (function(){ //点亮整颗 var LightEntire = function(el,options){ this.$el = $(el); this.$item = this.$el.find("rating-item"); this.opts = options; }; LightEntire.prototype.init = function(){ this.lightOn(this.opts.num); this.bindEvent(); }; LightEntire.prototype.lightOn = function(num){ num = parseInt(num); this.$item.each(function(index){ if(index < num){ $(this).css("background-position",'0 -67px'); }else{ $(this).css("background-position",'0 0'); } }); }; LightEntire.prototype.bindEvent = function(){ var self = this; self.$el.on("mouseover",".rating-item",function(){ self.lightOn($(this).index() + 1); }).on('click',".rating-item",function(){ self.opts.num = $(this).index()+1; }).on("mouseout",function(){ self.lightOn(self.opts.num); }) }; //默认参数 var defaults = { num:0, readOnly:false, select:function(){}, chosen:function(){} }; //初始化 var init = function(el,options){ options = $.extend({},defaults,options); new LightEntire(el,options).init(); }; return {init:init} })(); rating.init("#rating",{ num:2 }); </script>
对照了两遍,没有找到哪里写错了,求帮帮忙
this
.$item =
this
.$el.find(
"rating-item"
);应该是find('.rating-item')类名
星级评分原理和实现(上)
25809 学习 · 109 问题
相似问题