-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp01.html
More file actions
77 lines (76 loc) · 3.2 KB
/
app01.html
File metadata and controls
77 lines (76 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>자바스크립트 응용 01 - 계산기</title>
<style>
@font-face {
font-family: digital;
src: url("./digital-7.ttf");
}
* {font-size: 20px;}
input {width: 300px; height: 50px; border-radius: 5px; font-family: digital, sanserif; font-size: 30px; margin-top: 40px; background-color: rgba(250, 255, 195, 0.641); margin-bottom: 30px; text-indent: 8px;}
button {width: 60px; height: 60px; box-shadow: 1px 2px 1px 1px rgba(112, 128, 144, 0.8); border-radius: 100%;}
button:active{background-color: rgb(222, 222, 222); box-shadow: 1px 2px 1px 1px rgba(112, 128, 144, 0.8) inset;}
table {width: 100%;}
tr {display: flex; justify-content: space-between; margin-bottom: 10px;}
.cal_wrap {background-color: rgb(0, 107, 45); padding: 20px; width: fit-content; height: fit-content; border-radius: 10px; padding-bottom: 60px; box-shadow: 3px 3px 2px 1px rgba(112, 128, 144, 0.8);}
</style>
</head>
<body style="margin: 10px;">
<h2>상민이의 계산기</h2>
<div id="calculator" style="display: flex; justify-content: center; align-items: center;">
<div class="cal_wrap">
<input type="text" id="display">
<table>
<tr>
<td><button id="btn7">7</button></td>
<td><button id="btn8">8</button></td>
<td><button id="btn9">9</button></td>
<td><button id="btn/">/</button></td>
</tr>
<tr>
<td><button id="btn4">4</button></td>
<td><button id="btn5">5</button></td>
<td><button id="btn6">6</button></td>
<td><button id="btn*">*</button></td>
</tr>
<tr>
<td><button id="btn1">1</button></td>
<td><button id="btn2">2</button></td>
<td><button id="btn3">3</button></td>
<td><button id="btn-">-</button></td>
</tr>
<tr>
<td><button id="btn0">0</button></td>
<td><button id="btn.">.</button></td>
<td><button id="calc" onclick="calc()">=</button></td>
<td><button id="btn+">+</button></td>
</tr>
</table>
</div>
</div>
<script>
var btn = document.querySelectorAll("button[id^='btn']")
var display = document.getElementById("display");
for(var i=0; i<btn.length; i++){
btn[i].addEventListener("click", function(e){
display.value+=e.target.innerText;
})
}
display.addEventListener("keypress", function(e){
console.log(typeof(e))
display.value += e.target.innerText;
})
function calc(){
try {
display.value = eval(display.value);
} catch (error) {
display.value = "";
alert("input error");
}
}
</script>
</body>
</html>