-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
159 lines (145 loc) · 5.99 KB
/
index.html
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous">
<link rel="stylesheet" href="./style.css">
<link rel="icon" href="./Images/icon.jpg" type="image/icon type">
<title>Bé tập tính</title>
</head>
<body>
<div>
<br>
</div>
<div class="container">
<div class="row">
<div class="col">
Bé tập tính
</div>
</div>
<div class="row">
<div class="col-3">
Số thứ nhất:
</div>
<div class="col-5">
<input type="text" placeholder="Nhập số" id="a" onfocusout="check1();">
</div>
<div class="col-2">
<input id="add" type="radio" name="calc" value="+">
<label for="add">Cộng</label>
</div>
<div class="col-2">
<input id="subtract" type="radio" name="calc" value="-">
<label for="subtract">Trừ</label>
</div>
</div>
<div class="row">
<div class="col-3">
Số thứ hai:
</div>
<div class="col-5">
<input type="text" placeholder="Nhập số" id="b" onfocusout="check2();">
</div>
<div class="col-2">
<input id="multiply" type="radio" name="calc" value="*">
<label for="multiply">Nhân</label>
</div>
<div class="col-2">
<input id="divide" type="radio" name="calc" value="/">
<label for="divide">Chia</label>
</div>
</div>
<div class="row">
<div class="col-3">
Kết quả:
</div>
<div class="col-5">
<input type="text" id="result" readonly>
</div>
<button class="col-3" onclick="Calc();" id="btnTinh">
Tính
</button>
</div>
<div class="row">
<div class="col-3">
Thông báo:
</div>
<div class="col-5">
<label for="" id="lablenotification"></label>
</div>
</div>
</div>
<script type="text/javascript">
function Calc() {
var calculation = document.getElementsByName("calc");
var value;
var a = Number(document.getElementById("a").value);
var b = Number(document.getElementById("b").value);
if(document.getElementById("a").value == "" || document.getElementById("b").value =="" || isNaN(Number(document.getElementById("a").value)) || isNaN(Number(document.getElementById("b").value)))
{
document.getElementById("lablenotification").innerHTML = "Bạn phải nhập đủ hai số hợp lệ.";
}
else
{
if(calculation[0].checked)
{
document.getElementById("lablenotification").innerHTML = "";
document.getElementById("result").value = a + b;
}
else if(calculation[1].checked)
{
document.getElementById("lablenotification").innerHTML = "";
document.getElementById("result").value = a - b;
}
else if(calculation[2].checked)
{
document.getElementById("lablenotification").innerHTML = "";
document.getElementById("result").value = a * b;
}
else if(calculation[3].checked)
{
if(b != 0)
{
document.getElementById("lablenotification").innerHTML = "";
document.getElementById("result").value = a / b;
}
else
{
document.getElementById("result").value = "";
document.getElementById("lablenotification").innerHTML = "Không hợp lệ. (Không thể chia cho 0).";
}
}
else{
document.getElementById("lablenotification").innerHTML = "Bạn chưa chọn phép tính.";
}
}
}
function check1()
{
if(isNaN(Number(document.getElementById("a").value)))
{
document.getElementById("lablenotification").innerHTML = "Giá trị nhập ở ô <i>Số thứ nhất</i> không phải là số.";
}
else
{
document.getElementById("lablenotification").innerHTML = "";
}
}
function check2()
{
if(isNaN(Number(document.getElementById("b").value)))
{
document.getElementById("lablenotification").innerHTML = "Giá trị nhập ở ô <i>Số thứ hai</i> không phải là số.";
}
else
{
document.getElementById("lablenotification").innerHTML = "";
}
}
</script>
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js" integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js" integrity="sha384-w1Q4orYjBQndcko6MimVbzY0tgp4pWB4lZ7lr30WKz0vr/aWKhXdBNmNb5D92v7s" crossorigin="anonymous"></script>
</body>
</html>