简体   繁体   English

JQuery UI Slider Uncaught TypeError:无法读取未定义的属性“addClass”

[英]JQuery UI Slider Uncaught TypeError: Cannot read property 'addClass' of undefined

I've checked all of the questions on SO and I can't seem to find the answer.我已经检查了 SO 上的所有问题,但似乎找不到答案。 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如果我将整数直接放入字段中,那么这可行,但我想在设置脚本时动态设置参数

I'm running JQuery 1.11.1, JQuery UI stable (1.11.0) and touchpunch.我正在运行 JQuery 1.11.1、JQuery UI stable (1.11.0) 和 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.我也试过用相同的结果包装在自执行函数中。

(The slide function can be disregarded) (滑动功能可以无视)

This throws the exception这会引发异常

EDIT I'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.编辑我刚刚注意到,如果我单击滑块,则会引发异常,但是如果我然后按向右箭头键,则不会引发异常,并且数量将填充 value 属性。 I've pasted console output at the end of the question.我在问题的末尾粘贴了控制台输出。

$("#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"); 
[]

Give your variables ( window.settings.principal.* ) another look.再看看你的变量( window.settings.principal.* )。 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.确保它们不仅是有效数字,而且在上下文中有意义。

I've had the same problem.我遇到了同样的问题。 Just on a trial n error base, i've discovered that the problem lies within the parseInt() function.只是在试验 n 错误基础上,我发现问题出在 parseInt() 函数中。 I've removed the function and just used the raw data :我已经删除了这个函数,只使用了原始数据:

$("#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() 有什么问题,因为我不是那种技术人员,但我希望这对其他人有帮助。

Please check minimum and maximum values, min value should be less than max value.请检查最小值和最大值,最小值应小于最大值。

Please check below example for reference.请检查以下示例以供参考。

$( ".slider1"+blockid ).slider({
    range: "min",
    value:0,
    min: 100,
    max: 10000,
    step : 10000,
    animate:true,
    slide: function( event, ui ) {
        console.log(ui.value);
    },
    create: function(event,ui){
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 jQuery UI:未捕获的TypeError:无法读取未定义的属性“display” - jQuery UI: Uncaught TypeError: Cannot read property 'display' of undefined jQuery UI:未捕获的TypeError:无法读取未定义的属性'nodeType' - jQuery UI : Uncaught TypeError: Cannot read property 'nodeType' of undefined 未捕获的TypeError:无法读取属性'addClass' - Uncaught TypeError: Cannot read property 'addClass' 未捕获的TypeError:无法读取未定义的属性'setData'[Slider] - Uncaught TypeError: Cannot read property 'setData' of undefined[Slider] W3 Slider - 未捕获的类型错误:无法读取未定义的属性“类名” - W3 Slider - Uncaught TypeError: Cannot read property 'className' of undefined 未捕获的类型错误:无法读取图像 slider 的未定义属性“样式” - Uncaught TypeError: Cannot read property 'style' of undefined for image slider Facebook 滑块:未捕获的类型错误:无法读取未定义的属性“长度” - Facebook Slider: Uncaught TypeError: Cannot read property 'length' of undefined 无法动态加载jQuery UI-未捕获的TypeError:无法读取未定义的属性'ui' - Unable to load jQuery UI dynamically - Uncaught TypeError: Cannot read property 'ui' of undefined 未捕获(承诺)TypeError:无法读取未定义的属性“ ui5” - Uncaught (in promise) TypeError: Cannot read property 'ui5' of undefined Kendo ui:未捕获的类型错误:无法读取未定义的属性“toLowerCase” - Kendo ui: Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM