[code]<html>
<head>
<script type="text/javascript">
function plus() {
temp.value = num.value ; type.value = 1; num.value = "" }
function minus() {
temp.value = num.value ; type.value = 2; num.value = "" }
function mul() {
temp.value = num.value ; type.value = 3; num.value = "" }
function div() {
temp.value = num.value ; type.value = 4; num.value = "" }

function get_result() {
if(type.value==1) {num.value = parseInt(temp.value) + parseInt(num.value);}
if(type.value==2) {num.value = parseInt(temp.value) - parseInt(num.value);}
if(type.value==3) {num.value = parseInt(temp.value) * parseInt(num.value);}
if(type.value==4) {num.value = parseInt(temp.value) / parseInt(num.value);}
temp.value = "";
}

</script>
</head>

<body>
<input type="text" size="10" id="num"><br>
<input type="button" value="+" onclick="plus()">
<input type="button" value="-" onclick="minus()">
<input type="button" value="*" onclick="mul()">
<input type="button" value="/" onclick="div()"><br>
<input type="button" value="      =      " onclick="get_result()">
<input type="hidden" size="10" id="temp">
<input type="hidden" size="10" id="type">
</body>
</html>[/code]


 html 기반의 Javascript 를 이용한 계산기.

w3c school 참조 하였으며,
결과값을 이용한 연속 연산도 가능하도록 되어 있고,
JS 특성상 zero divisor 등에 대해서도 무한대 결과 출력이라던가,
정상적인 값이 아니면 non 이 뜨는 등 에러 처리도 된다.

(첫번째꺼 빼고는 ) 내가 일일이 다 구현한 것도 아니지만
JS 라서 다 된다...  -_-;;;



신기하다.
인터넷 응용프로그래밍 중간고사 치고 나니깐...
JS 로 뭔가 만드는게 좀 주저함이 많이 없어졌다.
이번에 중간고사때 실제 손 코딩은 처음 해봤는데도 이런다. ;;;

'Study.. > Programming' 카테고리의 다른 글

race condition ( thread, mutex, semaphore)  (0) 2009.05.29
no newline at end of file  (0) 2009.05.29
printf 의 16진수 / 8진수 출력..  (0) 2008.09.18
Intelligent completion at Vim 7.0  (0) 2008.06.03
_beginthreadex  (2) 2007.11.16
Posted by Yoons...
,