-
Notifications
You must be signed in to change notification settings - Fork 0
/
شعر.html
92 lines (78 loc) · 2.6 KB
/
شعر.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
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>جاوا اسکریپت: نمایش اشعار با حفظ فضای خالی و فاصله</title>
<link href="img/ui/favicon.ico" type="image/x-icon" rel="icon">
<style>
html,
pre {
font-family: Verdana, Geneva, Tahoma, sans-serif
}
body {
width: 700px;
margin: 0 auto;
background-color: #ccc;
}
pre {
line-height: 1.5;
letter-spacing: 0.05rem;
padding: 1rem;
background-color: white;
text-align: center;
}
label {
width: 200px;
margin-right: 33px;
}
select {
width: 350px;
padding: 5px;
}
</style>
</head>
<body>
<h1>جاوا اسکریپت: نمایش اشعار با حفظ فضای خالی و فاصله</h1>
<h2>استفاده از AJAX برای بروزرسانی صفحه</h2>
<form>
<label for="verse-choose">انتخاب نظم از منظومه</label>
<select id="verse-choose" name="verse-choose">
<option>شعر ۱</option>
<option>شعر ۲</option>
<option>شعر ۳</option>
<option>شعر ۴</option>
</select>
</form>
<h2>مثنوی معنوی, <em>مولانا جلالالدین محمد بلخی, ۶۰۴ هجری قمری</em></h2>
<pre>
</pre>
<script>
const verseChoose = document.querySelector('select');
const poemDisplay = document.querySelector('pre');
verseChoose.onchange = function () {
const verse = verseChoose.value;
updateDisplay(verse);
};
function updateDisplay(verse) {
verse = verse.replace(" ", "");
let url = verse + '.txt';
fetch(url)
.then(function (response) {
if (response.ok) {
console.log("Success");
return response.text(); //returns the response as raw text plus promise
} else {
console.log("Fetching is failed!")
}
})
.then(function (text) {
poemDisplay.textContent = text;
});
}
updateDisplay('شعر ۱');
verseChoose.value = 'شعر ۱';
</script>
</body>
</html>