quiz06.html
1.5 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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<title>test</title>
</head>
<body>
<div>
<input type="text" id="a">
<select id="op">
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select>
<input type="text" id="b">
</div>
<button type="button" id="exec">계산</button>
<span>result:</span>
<script type="text/javascript">
$(document).ready(function() {
$("button").click(function() {
var a = parseFloat(Number($("#a").val()));
var b = parseFloat(Number($("#b").val()));
if (isNaN(a) == true || isNaN(b) == true) {
alert("숫자를 입력하세요");
$("span").html("result = error");
} else {
var c = $("#op option:selected").val();
if (c == "+") {
var d = a + b;
$("span").html("result ="+d);
} else if (c == "-") {
$("span").html("result ="+d);
var d = a - b;
} else if (c == "*") {
var d = a * b;
$("span").html("result ="+d);
} else if (c == "/") {
if (b == 0) {
alert("0으로 나눌수 없음");
$("span").html("result = error");
} else {
var d = a / b;
$("span").html("result ="+d);
}
}
}
});
});
</script>
</body>
</html>