问答详情
源自:4-5 点亮整颗星星

一直报 Uncaught TypeError: Cannot set property 'init' of undefined at index3.js:10 at index3.js:57

var rating = (function () {


// 点亮整颗

var LightEntire = function (el, options) {

this.$el = $(el);

this.$itme = this.$el.find(".rating-item");

this.opts = options;

};


LightEntire.phototype.init = function () {

this.LightOn(this.opts.num);

this.bindEvent();

};


LightEntire.phototype.LightOn = function (num) {

num = parseInt(num);


this.$itme.each(function (index) {

if (index<num) {

$(this).css("background-color","yellow");

}else{

$(this).css("background-color","#EEE");

}

})

};


LightEntire.phototype.bindEvent = function () {

var self = this;


this.$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,

}); 


提问者:韶华_易逝 2018-09-27 16:53

个回答

  • 韶华_易逝
    2018-09-27 17:05:18

    吧  phototype 改成  prototype