我想写一个html代码来添加,减去,除或乘以两个或更多的数字,但我有困难...(我尝试添加一些CSS只是使它看起来不错,但我更关心代码运行第一)。我也在使用Javascript。请问我做错了什么?如何在HTML和Javascript中实现基本的计算器
<html>
<head>
<body bgcolor="FFFCC">
<table border="0" cellpadding="0"
cellspacing="1" sytyle ="border-collapse. collapse"
bordercolor="#1111" width ="50%">
<hi><p align="center">CALCULATOR</p></hi><br>
<script language= "javascript">
function ADD()
{
var first=parsefloat(txtNumber1.value);
var second=parsefloat(txtNumber2.value);
var Ans =first+second;
txtAnswer.value=Ans;
}
function MINUS()
{
var first=parsefloat(txtNumber1.value);
var second=parsefloat(txtNumber2.value);
var Ans =first-second;
txtAnswer.value=Ans;
function DIVIDE()
{
var first=parsefloat(txtNumber1.value);
var second=parsefloat(txtNumber2.value);
var Ans =first/second;
txtAnswer.value=Ans;
}
function MULTIPLY()
{
var first=parsefloat(txtNumber1.value);
var second=parsefloat(txtNumber2.value);
var Ans =first*second;
txtAnswer.value=Ans;
}
function MODULO()
{
var first=parsefloat(txtNumber1.value);
var second=parsefloat(txtNumber2.value);
var Ans =first%second;
txtAnswer.value=Ans;
}
</script>
</head>
<input type ="text" name="txtNumber1"/><br>
<input type ="text" name="txtNumber2"/><br>
<input type ="button" name="butAnswer"
value="+" onclick="ADD()"/>
<input type ="button" name="butAnswer"
value="-" onclick="MINUS()"/>
<input type ="button" name="butAnswer"
value="/" onclick="DIVIDE()"/>
<input type ="button" name="butAnswer"
value="*" onclick="MULTIPLY()"/>
<input type ="button" name="butAnswer"
value="%" onclick="MODULO()"/><br>
<input type ="text" name="txtAnswer"/>
</table>
</body>
</html>
感谢you..i'll检查 – Billz