【问题标题】:addClass causing undefined is not a functionaddClass 导致 undefined is not a function
【发布时间】:2015-04-20 02:29:38
【问题描述】:

我有:

mouseOver: function () {
   var catId = this.category_id;
   $('#expenditureSummaryGrid .k-grid-content tr').each(function() {
       if($('td span', this).data('id') == catId) {
           this.addClass('grid-hover');
       }
   })
},

但它给了我:

Uncaught TypeError: undefined is not a function

这没有多大意义,因为“this”是预期的 DOM 元素,我也在尝试添加一个类。

出了什么问题?

【问题讨论】:

    标签: javascript jquery jquery-selectors


    【解决方案1】:

    由于.addClass() 是一个 jQuery 函数,您可能需要更改

    this.addClass('grid-hover');
    

    $(this).addClass('grid-hover');
    

    【讨论】:

      【解决方案2】:

      "this" 的错误在于 for each 循环内的条件。可以试试吗

              mouseOver: function () {
                                  var catId = this.category_id;
                                  $('#expenditureSummaryGrid .k-grid-content tr').each(function(){
                                      if(this.find('td span').data('id') == catId) {
                                          this.addClass('grid-hover');
                                      }
                                  })
                              },
      

      【讨论】:

        猜你喜欢
        • 2012-06-05
        • 1970-01-01
        • 1970-01-01
        • 2015-06-24
        • 2021-06-21
        • 1970-01-01
        • 2015-06-13
        • 2014-08-15
        • 1970-01-01
        相关资源
        最近更新 更多