jQuery NoUiSlider无法使用最大值10

时间:2015-08-04 05:36:04

标签: javascript jquery nouislider

当我设置一个100的股票价值时,它就可以了。

此问题的实时副本位于:http://mypcdeals.com/product-list.php?c=motherboards#limit=20&p=0

产品搜索左下角的“SATA 3GB / S PORTS”滑块未正确格式化,最小值为0,最大值为10。

以下是应该设置它的代码:

      initPopulateRangeSliders: function () {
        $('.rangefilter').each(function () {
            var id = $(this).attr('id');
            //get the max value for this field 
            $.getJSON("/getSliderMax?f=" + id, function (data) {
                if (data.success)
                {
                    var theMax = data.max;
                    alert('Max should be set to:' + theMax);
                    var theSlider = document.getElementById(id);
                    var settings = {
                        start: 0,
                        behaviour: 'snap',
                        range: {
                            'min': 0,
                            'max': theMax
                        }
                    }
                    noUiSlider.create(theSlider, settings);
                }
            });
        });

如果您加载页面,您将看到警告框显示最大值,但我收到错误:

未捕获错误:noUiSlider:'range'包含无效值。

为什么?

2 个答案:

答案 0 :(得分:1)

initPopulateRangeSliders: function () {
    $('.rangefilter').each(function () {
        var id = $(this).attr('id');
        //get the max value for this field 
        $.getJSON("/getSliderMax?f=" + id, function (data) {
            if (data.success)
            {
                var theMax = data.max;
                alert('Max should be set to:' + theMax);
                var theSlider = document.getElementById(id);
                var settings = {
                    start: 0,
                    behaviour: 'snap',
                    range: {
                        'min': 0,
                        'max': parseInt(theMax)
                    }
                }
                noUiSlider.create(theSlider, settings);
            }
        });
    });

答案 1 :(得分:0)

有同样的问题。 原因是在输入中,初始最小值或最大值是值,其中的空格如“1 234”。请格式化初始数据。