간단한 계산기 만드는 스크립트

2011. 9. 23. 00:47컴퓨터_computer/JAVASCRIPT

<html>
<head>
<title>계산기</title>
<script>
bBool=false 
var copiedtext="" 
var tempstore="" 
function initiatecopy() { 
bBool=true; 
function copyit() { 
if (bBool) { 
tempstore=copiedtext 
document.execCommand("Copy") 
if (tempstore!=copiedtext) { 
alert(copiedtext); 
bBool=false; 
document.onselectionchange = initiatecopy 
document.onmouseup = copyit 
</script>
</head>
<script language="JavaScript">
function cal(p){
p.value=eval(p.value)
}
function e_expr(p,str){
p.value=p.value+str
}
function clear_expr(p){
p.value=""
}
</script>
<body>
<center>
    <form name="calform">
        <div align="left">
            <table border=30 bordercolor="silver" bordercolordark="silver">
<td colspan=4>
                    <p align="center"><input type="text" name="expr" size="20"></p>
<tr>
<tr>
                <td>
                    <p align="center"><input type="button" value=" 7 " onclick="e_expr(document.calform.expr,'7')">
</p>
<td>
                    <p align="center"><input type="button" value=" 8 " onclick="e_expr(document.calform.expr,'8')">
</p>
<td>
                    <p align="center"><input type="button" value=" 9 " onclick="e_expr(document.calform.expr,'9')">
</p>
<td>
                    <p align="center"><input type="button" value=" ÷ " onclick="e_expr(document.calform.expr,'/')">
</p>
<tr>
                <td>
                    <p align="center"><input type="button" value=" 4 " onclick="e_expr(document.calform.expr,'4')">
</p>
<td>
                    <p align="center"><input type="button" value=" 5 " onclick="e_expr(document.calform.expr,'5')">
</p>
<td>
                    <p align="center"><input type="button" value=" 6 " onclick="e_expr(document.calform.expr,'6')">
</p>
<td>
                    <p align="center"><input type="button" value=" × " onclick="e_expr(document.calform.expr,'*')">
</p>
<tr>
                <td>
                    <p align="center"><input type="button" value=" 1 " onclick="e_expr(document.calform.expr,'1')">
</p>
<td>
                    <p align="center"><input type="button" value=" 2 " onclick="e_expr(document.calform.expr,'2')">
</p>
<td>
                    <p align="center"><input type="button" value=" 3 " onclick="e_expr(document.calform.expr,'3')">
</p>
<td>
                    <p align="center"><input type="button" value=" - " onclick="e_expr(document.calform.expr,'-')">
</p>
<tr>
                <td>
                    <p align="center"><input type="button" value=" 0 " onclick="e_expr(document.calform.expr,'0')">
</p>
<td>
                        <p align="center"><input type="button" value=" 00 " onclick="e_expr(document.calform.expr,'00')">
</p>
<td>
                        <p align="center"><input type="button" value=" . " onclick="e_expr(document.calform.expr,'.')">
</p>
<td>
                        <p align="center"><input type="button" value=" + " onclick="e_expr(document.calform.expr,'+')">
</p>
<tr>
                    <td colspan=2>
                        <p align="center"><input type="button" value=" = " onclick="cal(document.calform.expr)">
</p>
<td colspan=2>
                    <p align="center"><input type="button" value="초기화" onclick="clear_expr(document.calform.expr)">
</p>
<tr>
</tr>
        </table>
    </div>
</form>
</center>
</body>
</html>
<body oncontextmenu="return false">


복잡한 계산은 하지 못하더라도 간단한 계산기 스크립트입니다.