<html>
<head>
<title>Calculator </title>
<script>
function compute(obj)
   {obj.expr.value = eval(obj.expr.value)}

var one = '1'
var two = '2'
var three = '3'
var four = '4'
var five = '5'
var six = '6'
var seven = '7'
var eight = '8'
var nine = '9'
var zero = '0'
var plus = '+'
var minus = '-'
var multiply = '*'
var divide = '/'
var decimal = '.'

function enter(obj, string)
   {obj.expr.value += string}

function clear(obj)
   {obj.expr.value = ''}

</script>
</head>

<body>


<form name="calc" method="get">

<table border="1" cellpadding="5">
<tr>
<td colspan="4">
<p align="center"><input type="text" name="expr" size="30" action="compute(this.form)"> </td>
</tr>
<tr>
<td><p align="center"><input type="button" value="  7  " onclick="enter(this.form, seven)">
</td>
<td><p align="center"><input type="button" value="  8  " onclick="enter(this.form, eight)">
</td>
<td><p align="center"><input type="button" value="  9  " onclick="enter(this.form, nine)">
</td>
<td><p align="center"><input type="button" value="   /  " onclick="enter(this.form, divide)">
</td>
</tr>
<tr>
<td><p align="center"><input type="button" value="  4  " onclick="enter(this.form, four)">
</td>
<td><p align="center"><input type="button" value="  5  " onclick="enter(this.form, five)">
</td>
<td><p align="center"><input type="button" value="  6  " onclick="enter(this.form, six)">
</td>
<td><p align="center"><input type="button" value="  *  " onclick="enter(this.form, multiply)">
</td>
</tr>
<tr>
<td><p align="center"><input type="button" value="  1  " onclick="enter(this.form, one)">
</td>
<td><p align="center"><input type="button" value="  2  " onclick="enter(this.form, two)">
</td>
<td><p align="center"><input type="button" value="  3  " onclick="enter(this.form, three)">
</td>
<td><p align="center"><input type="button" value="   -  " onclick="enter(this.form, minus)">
</td>
</tr>
<tr>
<td colspan="2"><p align="center"><input type="button" value="       0       "
onclick="enter(this.form, zero)"> </td>
<td><p align="center"><input type="button" value="   .  " onclick="enter(this.form, decimal)">
</td>
<td><p align="center"><input type="button" value="  +  " onclick="enter(this.form, plus)">
</td>
</tr>
<tr>
<td colspan="2"><p align="center"><input
type="button" value="   =   " onclick="compute(this.form)"> </td>
<td colspan="2"><p align="center"><input
type="reset" value="  AC  " onclick="clear(this.form)" size="3"> </td>
</tr>
</table>
</form>

</body>

</html>

'html, script' 카테고리의 다른 글

스톱워치 소스  (0) 2017.04.12
현재시간 시계 스크립트  (0) 2017.04.12
자바스크립트 기본 몇가지  (0) 2017.04.12
확인유무 경고창발생 confirm  (0) 2017.04.12
이벤트키 단축키 event.keycode  (0) 2017.04.12




+ Recent posts