2012-10-16 40 views
-3

找出计算器的代码时遇到问题。我已经使用我的教材寻求帮助,但仍然在为什么它根本不计算,只是一些提示会很棒请谢谢,谢谢。添加产品并将其与税率相乘的计算器

<html> 
<head> 
<title> Total Calculator </title> 
</head> 
<body> 
<p> 
Bananas: <input type="text" id="bananasBox" value=""> at $ 0.50 a piece<br> 
Sodas : <input type="text" id="sodasBox" value=""> at $ 0.75 per can<br> 
Chips : <input type="text" id="chipsBox" value=""> at $1.25 per bag<br> 
Candy : <input type="text" id="candyBox" value=""> at $1.00 per pack<br> 
TAX is 10 % 
</p> 
<input type="button" value="Calculate" 
<button id='Calculate' onclick= "Calculate()" value="Calculate">Calculate</button> 
<script type="text/javascript"> 


function Calculate() { 
    var total = 0; 
    var cost = document.getElementById("cost").value; 
    var tax = document.getElementById("tax").value; 

    total = cost*tax; 
    document.getElementById("total").value = total; 

document.getElementById('outputDiv').innerHTML= 'Your TOTAL is: ' + total;"> 
} 
</script> 
<hr> 
<div id="outputDiv"></div> 
</body> 
</html> 
+0

更改报价'计算总数'() – coolguy

+1

结束''在哪里'标签?为什么函数名称的引号是?我只是注意到,你似乎在'onlick'值中有整块...我真的建议回到一些JavaScript教程:http://www.w3.org/wiki/Your_first_look_at_JavaScript,http:// www.w3.org/wiki/Programming_-_the_real_basics,http://www.w3.org/wiki/Handling_events_with_JavaScript –

+0

用户意味着您应该删除引号,并且方法名中不应有空格 – pythonian29033

回答

1

您有许多问题。


HTML无效(按钮标记停止在onclick属性的中途)。

缺失<script>的结束标记。


在JavaScript函数声明的语法是:

function identifier() { } 

其中identifier是函数的名称。标识符不被引用,并且不能包含空格。


没有试图在代码中的任何地方调用你的函数。


您提出四个呼吁document.getElementById,但只有你试图访问存在ID之一。


你在它document.getElementById最后通话之前结束与}功能。

+0

继续并编辑@Quentin – user1739624

0

好吧,如果你完全按照你的教科书,那么我不认为你会面临这些问题。用空格

  1. 函数名
  2. 验证您的输入按钮的语法

2.1的onclick

2.2关闭标签

3关闭脚本标签