2013-09-21 126 views
0

我正在研究jQuery計算器。一切都很好,直到幾分鐘前,現在什麼都不會發生。我意外地在代碼中插入了一個壞字符嗎?我已經上下掃描了幾次,但找不到源代碼。任何幫助,將不勝感激!基本的jQuery計算器

頭:

<script src="http://code.jquery.com/jquery.js"></script> 
<link href="css/bootstrap.min.css" rel="stylesheet" media="screen"> 
<link rel="stylesheet" type="text/css" href="css/style-calc.css"> 
<script src="js/bootstrap.min.js"></script> 

的jQuery:

$(document).ready(function() { 
alert("ready"); 
$('#salary, #transcribing-hours, #cost-of-assistant').keydown(function(e){ 
    var key = e.which; 
    if (key != 8 && key != 9 && key != 37 && key != 38 && key != 39 && key != 40 && key != 46 && key != 110 && key != 190 && key != 13){ 
     if (key < 48){ 
      e.preventDefault(); 
     } 
     else if (key > 57 && key < 96){ 
      e.preventDefault(); 
     } 

     else if (key > 105) { 
      e.preventDefault(); 
     } 
    } 
}); 
}); 

$('#salary').on('input', function() { 
    var salary = $('#salary').val(); 
    var costofassist = $('#cost-of-assistant').val(); 
    var total = salary/(52 * 40); 
    var roundtotal = Math.round(total * 100)/100; 

    $('#hourly-pay-total').text(roundtotal); 

}); 

$('#transcribing-hours').on('input', function() { 
    var hoursday = $('#transcribing-hours').val(); 
    var hoursweek = hoursday * 5; 
    var hoursmonth = hoursweek * 4.3; 
    var hoursyear = hoursweek * 52; 

    $('#transcribing-year').text(Math.round(hoursyear * 100)/100); 
    $('#transcribing-month').text(Math.round(hoursmonth * 100)/100); 
    $('#transcribing-week').text(Math.round(hoursweek * 100)/100); 

    var roundtotal = $('#hourly-pay-total').text(); 
    var costwithoutyear = (hoursweek * roundtotal) * 52; 
    var costwithoutmonth = (hoursweek * roundtotal) * 4.3; 
    var costwithoutweek = hoursweek * roundtotal; 

    $('#cost-without-year').text(Math.round(costwithoutyear * 100)/100); 
    $('#cost-without-month').text(Math.round(costwithoutmonth * 100)/100); 
    $('#cost-without-week').text(Math.round(costwithoutweek * 100)/100); 

}); 

$('#cost-of-assistant').on('input', function() { 
    var costofassist = $('#cost-of-assistant').val(); 
    var costwithoutyear = $('#cost-without-year').text(); 
    var annualsavings = costwithoutyear - costofassist; 
    var monthlysavings = annualsavings/12; 
    var weeklysavings = annualsavings/52; 
    var dailysavings = annualsavings/260; 

    $('#annual-savings').text((Math.round(annualsavings * 100)/100); 
    $('#monthly-savings').text(Math.round(monthlysavings * 100)/100); 
    $('#weekly-savings').text(Math.round(weeklysavings * 100)/100); 
    $('#daily-savings').text(Math.round(dailysavings * 100)/100); 
}); 
+0

僅供參考:追蹤javascript中任何問題的最佳方法是在谷歌chtome中打開頁面,並按下'F12'作爲開發模式。它會告訴你這個問題。 –

回答

4

在你的jQuery的代碼行59是一個左括號太多。

$('#annual-savings').text((Math.round(annualsavings * 100)/100); 

應該是:

$('#annual-savings').text(Math.round(annualsavings * 100)/100); 

提示:如果您使用如Firefox或Safari,你有一個JavaScript控制檯,它可以檢測到這種語法錯誤。

0

我使用的螢火蟲插件,我很滿意它。在控制檯選項卡,它會顯示你發現的語法錯誤,如發現一個好。我使用mozilla,但我非常確定Chrome也支持它。你應該試試看。