javascript
  • jquery
  • 2012-12-18 150 views 2 likes 
    2

    我得到這個jQuery - Uncaught Type Error: string is not a function錯誤現在jQuery - 未捕獲類型錯誤:字符串不是函數

    什麼可能是錯誤的?

    下面是我的代碼

    $(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))' 
          }); 
         }); 
        } 
    
    }); 
    
    +2

    您將一個字符串分配給'slider',然後嘗試將其作爲函數調用。這不是一個功能,所以你會得到一個錯誤。什麼是'slider'意思是? –

    +0

    'slider'意思是在底部聲明的函數。儘管如此,你仍然在覆蓋它。 – Niko

    回答

    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); 
    
    相關問題