<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");
 怎么解决啊

解决方案 »

  1.   

     init: function() {
    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");
    }
      

  2.   


    我按照你的来现在是:ReferenceError: _this is not defined
      

  3.   


    我按照你的来现在是:ReferenceError: _this is not defined 
      

  4.   

    e = {
        me: this,
        init: {...},
        ...,
        onmouseenter:function(){
            me.addclass("list-hover");
        },
        ...
    }
      

  5.   

    你贴的代码格式凌乱,所以刚刚的写错了  
    bindEvent: function() {
               var _this = this;
                this.$bigCateItem.bind("mouseenter", this.onmouseenter);
               
            },onmouseenter:function(){
    _this.addclass("list-hover");
    }
      

  6.   

    厄 好吧,我承认我粗心且想多了,前面的请无视
    原来只是一个大小写问题
    bindEvent: function() {
               var _this = this;
                this.$bigCateItem.bind("mouseenter", this.onmouseenter);
               
            },onmouseenter:function(){
    this.addClass("list-hover");
      

  7.   

    var _this = this;
                this.$bigCateItem.bind("mouseenter",function(){_this.onmouseenter();} );
      

  8.   

    把onmouseenter去掉,bindEvent改成以下形式也许是楼主想要的效果 bindEvent: function() {
         this.$bigCateItem.bind("mouseenter", function(){
             $(this).addclass("list-hover");
          });    
      }
      

  9.   

    如果去深入了解javascript的机制,那么可以看出来this是指当前的活动对象,而js是基于函数作用域的作用域链,this只能指向当前的活动对象,this不是变量,是关键字。每进入一个函数,this都会发生变化。