<script type="text/javascript">
$(function(){
//alert("fdsa");
var e = {
init: function() {
this.$bigCateItem = $(".list-items");
this.$divmenu = $("#J_menu");
this.$ulmenu = $(".life-left-menu");
var j = this;
j.bindEvent()
},
bindEvent: function() {
this.$bigCateItem.bind("mouseenter", this.onmouseenter);
},onmouseenter:function(){
this.addclass("list-hover");
}
};
e.init()
})</script>现在报错:TypeError: this.addclass is not a function
[在此错误处中断] this.addclass("list-hover");
怎么解决啊
$(function(){
//alert("fdsa");
var e = {
init: function() {
this.$bigCateItem = $(".list-items");
this.$divmenu = $("#J_menu");
this.$ulmenu = $(".life-left-menu");
var j = this;
j.bindEvent()
},
bindEvent: function() {
this.$bigCateItem.bind("mouseenter", this.onmouseenter);
},onmouseenter:function(){
this.addclass("list-hover");
}
};
e.init()
})</script>现在报错:TypeError: this.addclass is not a function
[在此错误处中断] this.addclass("list-hover");
怎么解决啊
var _this = this;
this.$bigCateItem = $(".list-items");
this.$divmenu = $("#J_menu");
this.$ulmenu = $(".life-left-menu");
var j = this;
j.bindEvent()
},
bindEvent: function() {
this.$bigCateItem.bind("mouseenter", this.onmouseenter);
},onmouseenter:function(){
_this.addclass("list-hover");
}
我按照你的来现在是:ReferenceError: _this is not defined
我按照你的来现在是:ReferenceError: _this is not defined
me: this,
init: {...},
...,
onmouseenter:function(){
me.addclass("list-hover");
},
...
}
bindEvent: function() {
var _this = this;
this.$bigCateItem.bind("mouseenter", this.onmouseenter);
},onmouseenter:function(){
_this.addclass("list-hover");
}
原来只是一个大小写问题
bindEvent: function() {
var _this = this;
this.$bigCateItem.bind("mouseenter", this.onmouseenter);
},onmouseenter:function(){
this.addClass("list-hover");
}
this.$bigCateItem.bind("mouseenter",function(){_this.onmouseenter();} );
this.$bigCateItem.bind("mouseenter", function(){
$(this).addclass("list-hover");
});
}