我一直在試圖添加下面代碼中顯示的兩個不同變量,但無論我做了什麼,結果都是楠,這裏有什麼錯誤嗎?我嘗試了一段時間,但我找不到任何錯誤的代碼!在楠中添加兩個變量
<script type="text/javascript">
function showEstimate() {
switch (document.getElementById("cboCar").value) {
case "A":
document.getElementById("imgCar").src= "images/Accord.jpg";
carPrice = document.getElementById("txtEstPr").value;
break;
case "C":
document.getElementById("imgCar").src= "images/Civic.jpg";
carPrice = document.getElementById("txtEstPr").value;
break;
} // end of switch block.
//here, the UI has done processing cars pics
//display the price for cars
document.getElementById("txtEstPr").value= "$" + carPrice;
// end of the function named
{
var vchkSt= (300.99).toFixed();
var vchkLe= (750.99).toFixed();
var vchkGps= (1600.00).toFixed();
var tTotal = 0;
carPrice = Number(document.getElementById("txtBasePr").value);
if (document.getElementById("chkSt").checked)
tTotal += parseFloat(carPrice) + parseFloat(vchkSt);
if (document.getElementById("chkLe").checked)
tTotal += parseFloat(carPrice) + parseFloat(vchkLe);
if (document.getElementById("chkGps").checked ==true)
tTotal += parseFloat(carPrice) + parseFloat(vchkGps);
//displaying the total
document.getElementById("txtEstPr").value = "$" + tTotal;
}
} // end of function showEstimate
</script>
錯誤:'(300.99).toFixed;'和'Number(carPrice = document.getElementById(「txtEstPr」)value);' – epascarello 2014-12-02 21:16:49
你檢查過什麼'carPrice'?如果getElementById()失敗(例如錯誤的id),則carPrice將變爲null。 – 2014-12-02 21:16:51
我正在將carPrice設置爲getElememtbyId的值(「txtEstpr」) – sunnybouy91 2014-12-02 21:34:42