<html>
<head>
<title>덧셈/뺄셈 버튼으로 구현하기</title>
< type="text/">
var exp=0;
function show(obj)
{
var temp = obj.value;
cal(temp);
document.getElementById("condition").value += temp;
}
function erase()
{
var erase='';
document.getElementById("condition").value = erase;
document.getElementById("result").value = erase;
}
function cal(a)
{
exp += a;
}
function compute()
{
if(eval(exp)=="")
{
alert("입력형식이 잘못 되었습니다. 다시 입력해 주세요") ; <-------------------------------------- 2/0 했을때 이게 왜 안뜰까요?
}
document.getElementById("result").value = eval(exp);
exp=0;
}
</>
</head>
<body>
덧셈/뺄셈 버튼 계산기
<br>
<form>
<input type="button" value="1" ="show(this)">
<input type="button" value="2" ="show(this)">
<input type="button" value="3" ="show(this)"><br>
<input type="button" value="4" ="show(this)">
<input type="button" value="5" ="show(this)">
<input type="button" value="6" ="show(this)"><br>
<input type="button" value="7" ="show(this)">
<input type="button" value="8" ="show(this)">
<input type="button" value="9" ="show(this)"><br>
<input type="button" value="0" ="show(this)">
<input type="button" value="+" ="show(this)">
<input type="button" value="-" ="show(this)">
<input type="button" value="*" ="show(this)">
<input type="button" value="/" ="show(this)"><br><br>
<input type="button" value="계산하기" ="compute()">
<input type="button" value="다 시" ="erase()"><br>
상태<input type="text" readonly id="condition"><br>
계산결과<input type="text" readonly id="result">
</form>
</body>
</html>
ㅄ 졸렬한놈 댓글지우넼ㅋㅋㅋㅋㅋ [할라할라할라할라]