jQuery UI slider - Cannot call method 'addClass' of undefined

后端 未结 7 1478
我在风中等你
我在风中等你 2021-01-07 21:50

I had this old jQuery UI slider that had worked just fine a few months ago, but now I seem to be getting an exception reading: Cannot call method \'addClass\' of undefined.

7条回答
  •  半阙折子戏
    2021-01-07 22:28

    For anyone who's still having this issue, ensure that the values you're adding (min, max, and values are all NUMBERS and not STRINGS!

    Been trying to diagnose a problem where the following code was failing:

    t.slider({
      range : true,
      min   : t.attr('data-min'),
      max   : t.attr('data-max'),
      values: [t.attr('data-min'), t.attr('data-max')],
      step  : 1.00,
      slide : function (e, ui) {
        var
          v = (s == 'price') ? '£' + ui.values[0] + ' - £' + ui.values[1] : ui.values[0] + ' - ' + ui.values[1] + 'kg'
        $('#filter-' + s).html(v)
      },
      stop  : function () {
        Items.filter()
      }
    })
    

    As t.attr() returns a STRING, Slider was failing to set valueMouse on line 12843 of Version 1.10.1 of jQuery UI. Instead of being a value, it was returning a string (something similar to 39.99549.21 (min value of 39.99 concatenated with 549.21 - a percentage * max value)

    Hope that helps someone!

提交回复
热议问题