javascript JQuery UI Slider Uncaught TypeError:无法读取未定义的属性“addClass”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24922008/
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 Uncaught TypeError: Cannot read property 'addClass' of undefined
提问by LiamRyan
I've checked all of the questions on SO and I can't seem to find the answer. If I place integers directly into the fields then this works but I want to set the parameters dynamically when I set up my script
我已经检查了 SO 上的所有问题,但似乎找不到答案。如果我将整数直接放入字段中,那么这可行,但我想在设置脚本时动态设置参数
I'm running JQuery 1.11.1, JQuery UI stable (1.11.0) and touchpunch. I've debugged and the variables are all present and initialised when this is invoked. I've also tried wrapping in self-executing functions with the same results.
我正在运行 JQuery 1.11.1、JQuery UI stable (1.11.0) 和 touchpunch。我已经调试并且变量都存在并且在调用时初始化。我也试过用相同的结果包装在自执行函数中。
(The slide function can be disregarded)
(滑动功能可以无视)
This throws the exception
这会引发异常
EDITI've just noticed that if I click on the slider the exception is thrown but if I then press the right arrow key no exception is thrown and the amount is populated with the value property. I've pasted console output at the end of the question.
编辑我刚刚注意到,如果我单击滑块,则会引发异常,但是如果我然后按向右箭头键,则不会引发异常,并且数量将填充 value 属性。我在问题的末尾粘贴了控制台输出。
$("#slider").slider({
value: parseInt(window.settings.principal.minimum),
min: parseInt(window.settings.principal.minimum),
max: parseInt(window.settings.principal.maximum),
step: parseInt(window.settings.principal.increment),
slide: function(event, ui) {
$( "#amount" ).val( "$" + $( "#slider").slider( "value"));
}
});
However this WILL work
然而这将工作
$("#slider").slider({
value: 500,
min: 500,
max: 10000,
step: 500,
slide: function(event, ui) {
$( "#amount" ).val( "$" + $( "#slider").slider( "value"));
}
});
Console Output
控制台输出
jQuery("#slider").slider("value");
5000
jQuery("#slider").slider("min");
Error: no such method 'min' for slider widget instance
jQuery("#slider").slider("minimum");
Error: no such method 'minimum' for slider widget instance
jQuery("#slider").slider("max");
Error: no such method 'max' for slider widget instance
jQuery("#slider").slider("interval");
Error: no such method 'interval' for slider widget instance
jQuery("#slider").slider("step");
Error: no such method 'step' for slider widget instance
jQuery("#slider").slider("values");
[]
采纳答案by Chris
Give your variables (window.settings.principal.*
) another look. I just copied your source code, replaced them with my own, and it worked, so your code seems to be fine. Make sure that they're not only valid numbers, but that they make sense in context.
window.settings.principal.*
再看看您的变量 ( )。我只是复制了你的源代码,用我自己的替换了它们,它工作了,所以你的代码似乎没问题。确保它们不仅是有效数字,而且在上下文中有意义。
回答by costin.cosmeanu
I've had the same problem. Just on a trial n error base, i've discovered that the problem lies within the parseInt() function. I've removed the function and just used the raw data :
我遇到了同样的问题。只是在试验 n 错误基础上,我发现问题出在 parseInt() 函数中。我已经删除了这个函数,只使用了原始数据:
$("#slider").slider({
value: window.settings.principal.minimum,
min: window.settings.principal.minimum,
max: window.settings.principal.maximum,
step: window.settings.principal.increment
});
It seems we're copying an old piece of snippet for the slider. I have no ideea what is wrong with parseInt() in this setup, as i'm not that technical, but i hope this helps others.
似乎我们正在复制滑块的旧片段。我不知道在这个设置中 parseInt() 有什么问题,因为我不是那么技术,但我希望这可以帮助其他人。