2016-06-13 81 views
-1

我有一個jsfiddle範圍滑塊工作良好,直到以前。Js不工作,雖然沒有錯誤

不知道出了什麼問題,也找不到錯誤。

基本上它的6個範圍滑塊可以根據滑塊的位置得到一個總結果。

$(document).ready(function() { 
     $("#slider1").slider({ 
      min: 0, 
      max: 100, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     $("#slider2").slider({ 
      min: 0, 
      max: 250, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     $("#slider3").slider({ 
      min: 0, 
      max: 100, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     $("#slider4").slider({ 
      min: 0, 
      max: 100, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     $("#slider5").slider({ 
      min: 0, 
      max: 100, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     $("#slider6").slider({ 
      min: 0, 
      max: 100, 
      slide: function(event, ui) { 
       update(); 
      } 
     }); 

     update(); }; 
    }), 

    function update() { 
     $("#amount").val($amount1); 
     $("#amount2").val($amount2); 
     $("#amount3").val($amount3); 
     $("#amount4").val($amount4); 
     $("#amount5").val($amount5); 
     $("#amount6").val($amount6); 
     $("#amount7").val($amount7); 
     $("#gbamount").val($gbamount); 
     $("#gbamount2").val($gbamount2); 
     $("#gbamount3").val($gbamount3); 
     $("#gbamount4").val($gbamount4); 
     $("#gbamount5").val($gbamount5); 
     $("#gbamount6").val($gbamount6); 

    $amount1 = $("#slider1").slider("values", 0); 
    $amount2 = $("#slider2").slider("values", 0); 
    $amount3 = $("#slider3").slider("values", 0); 
    $amount4 = $("#slider4").slider("values", 0); 
    $amount5 = $("#slider5").slider("values", 0); 
    $amount6 = $("#slider6").slider("values", 0); 
    $gbamount = ($amount1 * 3/1024).toFixed(2); 
    $gbamount2 = ($amount2 * 30/10240).toFixed(2); 
    $gbamount3 = ($amount3 * (1.43333333 * 30)/1024).toFixed(2); 
    $gbamount4 = ($amount4 * (10 * 60)/8/1024).toFixed(2); 
    $gbamount5 = ($amount5 * (30 * 60)/8/1024).toFixed(2); 
    $gbamount6 = ($amount6 * (30 * 0.1666666667)/1024).toFixed(2); 
    $amount7 = ($gbamount + $gbamount2 + $gbamount3 + $gbamount4 + $gbamount5 + $gbamount6).toFixed(2); 

    }; 

https://jsfiddle.net/jossiossi/b7tqtwnL/2/

+0

這似乎是你錯過了添加jQuery滑塊插件。 '''Uncaught TypeError:$(...)。滑塊不是我的控制檯輸出中打印的函數。 – andorx

+0

你忘記了'var'聲明。 –

+0

你是對的! :) – Ossi

回答

0

你好,請務必包括圖書館這裏

<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 

檢查

<!doctype html> 
<html lang="en"> 
<head> 
    <meta charset="utf-8"> 
    <title>jQuery UI Slider - Default functionality</title> 
    <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css"> 
    <script src="//code.jquery.com/jquery-1.10.2.js"></script> 
    <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script> 
    <link rel="stylesheet" href="/resources/demos/style.css"> 
    <script> 
    $(function() { 
    $("#slider").slider(); 
    }); 
    </script> 
</head> 
<body> 

<div id="slider"></div> 


</body> 
</html> 
0

這裏是更新的小提琴

http://jsfiddle.net/b7tqtwnL/4/

$(document).ready(function() { 
function update() { 

$amount1 = $("#slider1").slider("values", 0); 
$amount2 = $("#slider2").slider("values", 0); 
$amount3 = $("#slider3").slider("values", 0); 
$amount4 = $("#slider4").slider("values", 0); 
$amount5 = $("#slider5").slider("values", 0); 
$amount6 = $("#slider6").slider("values", 0); 
$gbamount = ($amount1 * 3/1024).toFixed(2); 
$gbamount2 = ($amount2 * 30/10240).toFixed(2); 
$gbamount3 = ($amount3 * (1.43333333 * 30)/1024).toFixed(2); 
$gbamount4 = ($amount4 * (10 * 60)/8/1024).toFixed(2); 
$gbamount5 = ($amount5 * (30 * 60)/8/1024).toFixed(2); 
$gbamount6 = ($amount6 * (30 * 0.1666666667)/1024).toFixed(2); 
console.log($gbamount + $gbamount2 + $gbamount3 + $gbamount4 + $gbamount5 + $gbamount6) 
$amount7 = (Number($gbamount) + Number($gbamount2)+ Number($gbamount3) + Number($gbamount4) + Number($gbamount5) + Number($gbamount6)).toFixed(2); 
    $("#amount").val($amount1); 
    $("#amount2").val($amount2); 
    $("#amount3").val($amount3); 
    $("#amount4").val($amount4); 
    $("#amount5").val($amount5); 
    $("#amount6").val($amount6); 
    $("#amount7").val($amount7); 
    $("#gbamount").val($gbamount); 
    $("#gbamount2").val($gbamount2); 
    $("#gbamount3").val($gbamount3); 
    $("#gbamount4").val($gbamount4); 
    $("#gbamount5").val($gbamount5); 
    $("#gbamount6").val($gbamount6); 


}; 
    $("#slider1").slider({ 
     min: 0, 
     max: 100, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    $("#slider2").slider({ 
     min: 0, 
     max: 250, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    $("#slider3").slider({ 
     min: 0, 
     max: 100, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    $("#slider4").slider({ 
     min: 0, 
     max: 100, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    $("#slider5").slider({ 
     min: 0, 
     max: 100, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    $("#slider6").slider({ 
     min: 0, 
     max: 100, 
     slide: function(event, ui) { 
      update(); 
     } 
    }); 

    //update(); }; 
})