jQuery - 未捕获类型错误:字符串不是函数

时间:2012-12-18 10:35:12

标签: javascript jquery

我现在收到此jQuery - Uncaught Type Error: string is not a function错误

可能出现什么问题?

以下是我的代码

$(function(){
    $('#tabs').tabs();
    inputs = $('input[type="range"]#defaultSlider');
    slider = '#slider-one';
    tab = '#tabs-1';
    slider(inputs,slider,tab);

    var firstTab = $('#tabs ul li')[0];
    var secondTab = $('#tabs ul li')[1];
    $(firstTab).live('click',function(){
        $('#slider-two').hide();
        $('#slider-one').show();
        inputs = $('input[type="range"]#defaultSlider');
        slider = '#slider-one';
        tab = '#tabs-1';
        slider(inputs,slider,tab);
    });
    $(secondTab).live('click',function(){
        $('#slider-two').show();
        $('#slider-one').hide();
        inputs = $('input[type="range"]#defaultSlider-2');
        slider = '#slider-two';
        tab = '#tabs-2';
        slider(inputs,slider,tab);
    });

    function slider(inputs, slider, tab){
        $(inputs).live('change',function (event) {
            console.log(inputs);
            var updatedRangeValue = event.target.value;
            var currentValue = updatedRangeValue - 1
            currentStep = $(slider + ' dl.steps dt')[currentValue];
            $(slider + ' dl.steps dt').removeClass('active');
            $(currentStep).addClass('active');
            var currentArticle = $(tab + ' article')[currentValue];
            $(tab + ' article').hide();
            $(currentArticle).show();

            value = (event.target.value - event.target.min)/(event.target.max - event.target.min);
            $(event.target).css({
                backgroundImage: '-webkit-gradient(linear, left top, right top, color-stop(' + value + ', #007fb0), color-stop(' + value + ', #024069))'
            });
        });
    }

});

1 个答案:

答案 0 :(得分:5)

您的变量名称存在冲突:

    slider = '#slider-one';     // You re-define `slider` here
    tab = '#tabs-1';
    slider(inputs,slider,tab);  // Then you try to call the original `slider`

slider重命名为其他内容,它应该可以正常工作(你有两个看起来像这样的代码块):

    slider1 = '#slider-one';
    tab = '#tabs-1';
    slider(inputs,slider1,tab);
相关问题