웹마스터 팁

계산기

2008.11.29 20:25

*이종민*

계산기 소스입니다.

<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">