[javascript] 전자 계산기 자바스크립트
로빈아빠
본문
<html>
<head>
<script>
function press(com){
s1=document.screen.display
s2=document.screen.expr
if (com=="=")
{if(s1.value==""){s1.value=eval(s2.value)}
else {s1.value=eval(s1.value);}}
else if (com=="ac")
{s1.value="";s2.value=""}
else{document.screen.display.value+=com}
}
//eval 을 거쳐야지만 문자가 아닌 숫자로 된다.
function off(){
document.bgColor="black"
}
function on(){
document.bgColor="orange"
}
</script>
</head>
<body>
<form name="screen">
<table border=1 bordercolor="#3399FF" height="30">
<tr>
<td colspan=4><input type="text" name="display" onFocus="blur()"></td>
</tr>
<tr>
<td bgcolor="#00FFFF"><input type="button" value=" 1 " onClick="press('1')"></td>
<td bgcolor="#00CCFF"><input type="button" value=" 2 " onClick="press('2')"></td>
<td bgcolor="#0099FF"><input type="button" value=" 3 " onClick="press('3')"></td>
<td bgcolor="#0066FF"><input type="button" value=" ÷ " onClick="press('/')"></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><input type="button" value=" 4 " onClick="press('4')"></td>
<td bgcolor="#FFCC00"><input type="button" value=" 5 " onClick="press('5')"></td>
<td bgcolor="#FF9900"><input type="button" value=" 6 " onClick="press('6')"></td>
<td bgcolor="#FF6600"><input type="button" value=" × " onClick="press('*')"></td>
</tr>
<tr>
<td bgcolor="#00FF00"><input type="button" value=" 7 " onClick="press('7')"></td>
<td bgcolor="#00CC00"><input type="button" value=" 8 " onClick="press('8')"></td>
<td bgcolor="#009900"><input type="button" value=" 9 " onClick="press('9')"></td>
<td bgcolor="#006600"><input type="button" value=" - " onClick="press('-')"></td>
</tr>
<tr>
<td bgcolor="#99CC00"><input type="button" value=" 0 " onClick="press('0')"></td>
<td bgcolor="#996600"><input type="button" value=" . " onClick="press('.')"></td>
<td bgcolor="#993300"><input type="button" value=" % " onClick="press('%')"></td>
<td bgcolor="#990033"><input type="button" value=" + " onClick="press('+')"></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><input type="button" value=" ac " onClick="press('ac')"></td>
<td bgcolor="#CC66FF"><input type="button" value=" on " onClick=on()></td>
<td bgcolor="#9900FF"><input type="button" value=" off " onClick=off()></td>
<td bgcolor="#663399"><input type="button" value=" = " onClick="press('=')"></td>
</tr>
<TR>
<TD COLSPAN=4><INPUT TYPE=TEXT NAME=expr></TD>
<TR>
</table>
</body>
</html>
[이 게시물은 VIRHAC님에 의해 2009-09-13 14:40:14 HTML에서 이동 됨]
<head>
<script>
function press(com){
s1=document.screen.display
s2=document.screen.expr
if (com=="=")
{if(s1.value==""){s1.value=eval(s2.value)}
else {s1.value=eval(s1.value);}}
else if (com=="ac")
{s1.value="";s2.value=""}
else{document.screen.display.value+=com}
}
//eval 을 거쳐야지만 문자가 아닌 숫자로 된다.
function off(){
document.bgColor="black"
}
function on(){
document.bgColor="orange"
}
</script>
</head>
<body>
<form name="screen">
<table border=1 bordercolor="#3399FF" height="30">
<tr>
<td colspan=4><input type="text" name="display" onFocus="blur()"></td>
</tr>
<tr>
<td bgcolor="#00FFFF"><input type="button" value=" 1 " onClick="press('1')"></td>
<td bgcolor="#00CCFF"><input type="button" value=" 2 " onClick="press('2')"></td>
<td bgcolor="#0099FF"><input type="button" value=" 3 " onClick="press('3')"></td>
<td bgcolor="#0066FF"><input type="button" value=" ÷ " onClick="press('/')"></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><input type="button" value=" 4 " onClick="press('4')"></td>
<td bgcolor="#FFCC00"><input type="button" value=" 5 " onClick="press('5')"></td>
<td bgcolor="#FF9900"><input type="button" value=" 6 " onClick="press('6')"></td>
<td bgcolor="#FF6600"><input type="button" value=" × " onClick="press('*')"></td>
</tr>
<tr>
<td bgcolor="#00FF00"><input type="button" value=" 7 " onClick="press('7')"></td>
<td bgcolor="#00CC00"><input type="button" value=" 8 " onClick="press('8')"></td>
<td bgcolor="#009900"><input type="button" value=" 9 " onClick="press('9')"></td>
<td bgcolor="#006600"><input type="button" value=" - " onClick="press('-')"></td>
</tr>
<tr>
<td bgcolor="#99CC00"><input type="button" value=" 0 " onClick="press('0')"></td>
<td bgcolor="#996600"><input type="button" value=" . " onClick="press('.')"></td>
<td bgcolor="#993300"><input type="button" value=" % " onClick="press('%')"></td>
<td bgcolor="#990033"><input type="button" value=" + " onClick="press('+')"></td>
</tr>
<tr>
<td bgcolor="#CCCCFF"><input type="button" value=" ac " onClick="press('ac')"></td>
<td bgcolor="#CC66FF"><input type="button" value=" on " onClick=on()></td>
<td bgcolor="#9900FF"><input type="button" value=" off " onClick=off()></td>
<td bgcolor="#663399"><input type="button" value=" = " onClick="press('=')"></td>
</tr>
<TR>
<TD COLSPAN=4><INPUT TYPE=TEXT NAME=expr></TD>
<TR>
</table>
</body>
</html>
[이 게시물은 VIRHAC님에 의해 2009-09-13 14:40:14 HTML에서 이동 됨]
관련링크
댓글목록
등록된 댓글이 없습니다.