javascript jQuery UI 滑块 - 无法调用未定义的方法“addClass”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11728079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery UI slider - Cannot call method 'addClass' of undefined
提问by SCS
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. I've checked the values being passed into the slider and they're regular Javascript dates.
几个月前我有这个旧的 jQuery UI 滑块,它工作得很好,但现在我似乎收到了一个异常读数:无法调用未定义的方法“addClass”。我检查了传递到滑块的值,它们是常规的 Javascript 日期。
$('#dateFilter').click(function() {
return $('#sliderContainer').slideToggle(200);
});
$(function() {
var endFiling, startFiling;
startFiling = Date.parse($('#startFiling').val());
endFiling = Date.parse($('#endFiling').val());
return $('#filingDateSlider').slider({
range: true,
min: startFiling,
max: endFiling,
step: 86400000,
values: [startFiling, endFiling],
slide: function(event, ui) {
var eD, end, sD, start;
sD = new Date(ui.values[0]);
start = dateFormat(sD);
eD = new Date(ui.values[1]);
end = dateFormat(eD);
$('#filingStartDate').text(start);
return $('#filingEndDate').text(end);
}
});
Is there a particular reason why I might be getting this new error?
我可能会收到这个新错误有什么特别的原因吗?
回答by Vinay
For anyone reading back on this question, if you're pulling from a CDN, try pulling from the latest jQuery UI version. I also got this problem, and it was solved by using a later jQuery UI version.
对于任何阅读此问题的人,如果您从 CDN 中提取,请尝试从最新的 jQuery UI 版本中提取。我也遇到了这个问题,通过使用较新的 jQuery UI 版本解决了。
回答by Miguel Gil Martínez
I solved this error by using integers in "min", "max" and "values". Maybe you are setting null values.
我通过在“min”、“max”和“values”中使用整数解决了这个错误。也许您正在设置空值。
The jQuery Slider specification says:
jQuery Slider 规范说:
- max Number Default:100
- min Number Default:0
- value Number Default: 0
- 最大数量默认值:100
- 最小数字默认值:0
- 值编号默认值:0
So "values" are an array of numbers.
所以“值”是一个数字数组。
回答by Alex
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!
对于谁仍然有这个问题的人,请确保您要添加的值(min
,max
,和values
都为数字,而不是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)
作为t.attr()
返回字符串,Slider 未能valueMouse
在 jQuery UI 版本 1.10.1 的第 12843 行设置。它不是一个值,而是返回一个字符串(类似于39.99549.21
(39.99
连接的最小值549.21
- 百分比 * 最大值)
Hope that helps someone!
希望对某人有所帮助!
回答by Dino
I had this issue with latest versions, too. The solution is easy: use parseInt()to pass dynamic values to sliders
Setter example for jquery ui slider:
我的最新版本也有这个问题。解决方案很简单:使用parseInt()将动态值传递给滑块
jQuery ui 滑块的 Setter 示例:
$("#mySlider").slider("option",{min: parseInt(value.min), max:parseInt(value.max),value: parseInt(value.active)});
回答by JvR
Another possibility - this error can come up if the min or max are missing for the slider. If your startFiling or endFiling are not evaluating to a date, the slider code fails when trying to calculate the new handle position.
另一种可能性 - 如果滑块缺少最小值或最大值,则会出现此错误。如果您的 startFiling 或 endFiling 未评估日期,则滑块代码在尝试计算新的手柄位置时会失败。
回答by brian
solved the problem using unmodified jQuery-UI.min.js. Using a custom script caused the error i.e jQuery-UI-custom.js
使用未修改的 jQuery-UI.min.js 解决了这个问题。使用自定义脚本导致错误,即 jQuery-UI-custom.js
回答by Shailesh Bhardwaj
jQuery UI Slider plugin min & max optionsaccepts only number. So according to your requirement parse them to integer or float.
jQuery UI Slider 插件最小和最大选项只接受数字。因此,根据您的要求将它们解析为整数或浮点数。
For details visit link- http://api.jqueryui.com/slider/
详情请访问链接- http://api.jqueryui.com/slider/