-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathตามพจนุกรม 10ประโยค.txt
102 lines (50 loc) · 1.65 KB
/
ตามพจนุกรม 10ประโยค.txt
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>QE </title>
</head>
<style>
body {
padding-top: 50px
}
</style>
</head>
<body>
<input type="text" id="text1"></input>
<input type="button" id="button1" value="Add" onclick="add_array();"></input>
<input type="button" id="button2" value="Display" onclick="display_array();"></input>
<div id="Result"></div>
<script type="text/javascript">
let x = 1;
let array = Array();
function add_array() {
// array[x] = document.getElementById("text1").value;
var text = document.getElementById("text1").value;
console.log(text);
if(text==""){
alert("รับแต่ข้อความ");
}else{
if (x >= 5) alert("ข้อความครบแล้ว ");
else {
array[x] = text;
alert(` รับ:${array[x]} เป็นข้อความที่ ${x}`);
x++;
}
}
//ที่เหลือก็แก่เอา เรื่อง array x มันเริ่มจาก 0
document.getElementById("text1").value = "";
}
//-----------------------------------------------------------------
function display_array() {
let e = "<hr/>";
for (let y = 0; y < array.length - 1; y++) {
array.sort();
e += `ข้อความที่ ${y + 1} = ${array[y]}<br/>`;
}
document.getElementById("Result").innerHTML = e;
}
</script>
</body>
</html>