我想寫一個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