當我點擊計算按鈕時,我似乎無法得到輸出。我知道這是一件簡單的事情,但我一整天都在絞盡腦汁,似乎無法讓它正常工作。這是我更新的代碼,但仍然無效。有人可以幫助我瞭解我做錯了什麼嗎?
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function calc(){
var price = document.getElementById("price");
var shipping=parseFloat(calc(price));
var total= price+shipping;
if (price<=25){
return 1.5;
}
else{
return price*10/100
}
window.alert("Your total price with shipping and handling is $" + price + ".");
}
</script>
</head>
<body>
<form name="total" action="">
Enter your amount:
<input type="text" name="price" id="price">
<input type="button"
value="calculate"
onclick="calc(document.getElementById("price")">
</form>
</body>
</html>
沒有'document.totalprice'元素。看看你的瀏覽器的錯誤控制檯。 – lonesomeday
看起來你有很多基本的錯誤。要做的最好的事情就是嘗試一個像codeacademy這樣的在線JavaScript教程,並學習基本的語法 –