This repository has been archived by the owner on Jun 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqznews.html
127 lines (108 loc) · 3.24 KB
/
qznews.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
<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>信息栏</title>
</head>
<style>
body {
font-size: 16px;
}
a {
text-decoration: none;
}
.info-bar {
padding: 20px;
}
.info-bar h2 {
font-size: 10px;
margin-bottom: 10px;
margin-top: 0;
/* 移除标题上方的默认外边距 */
}
.info-bar ul {
list-style-type: none;
padding-left: 0;
margin-bottom: 0;
/* 可选,移除列表下方的外边距,使底部更整洁 */
}
.info-bar li {
display: flex;
align-items: center;
margin-bottom: 10px;
}
.info-bar .date {
color: #6c757d;
margin-right: 10px;
}
.info-bar .title {
flex-grow: 1;
}
.container {
display: flex;
justify-content: space-between;
/* 保持不变,用于均匀分配空间 */
align-items: flex-start;
/* 确保内容从顶部对齐 */
}
.date {
white-space: nowrap;
/*日期不要换行*/
}
.column {
width: 380px;
padding: 20px;
box-sizing: border-box;
/* 确保内边距被包含在总宽度内 */
}
</style>
<body>
<div class="container">
<div class="column info-bar" id="news-column">
<img src="./img/infobar/qxxw.png" alt="">
<ul id="news-list"></ul>
</div>
<div class="column info-bar" id="media-column">
<img src="./img/infobar/mtqx.png" alt="">
<ul id="media-list"></ul>
</div>
<div class="column info-bar" id="teaching-research-column">
<img src="./img/infobar/qxxw.png" alt="">
<ul id="teaching-research-list"></ul>
</div>
</div>
</body>
<script>
// 从json中读取数据,然后显示到界面中
function processInfobar(data, listId) {
const list = document.getElementById(listId);
data.forEach(item => {
const listItem = document.createElement('li');
const dateElement = document.createElement('span');
dateElement.className = 'date';
dateElement.textContent = item.date;
const titleElement = document.createElement('a');
titleElement.href = item.url;
titleElement.textContent = item.title;
listItem.appendChild(dateElement);
listItem.appendChild(titleElement);
list.appendChild(listItem);
});
}
Promise.all([
fetch('./json/infobar1.json'),
fetch('./json/infobar2.json'),
fetch('./json/infobar3.json')
])
.then(([infobar1Response, infobar2Response, infobar3Response]) =>
Promise.all([infobar1Response.json(), infobar2Response.json(), infobar3Response.json()])
)
.then(([infobar1Data, infobar2Data, infobar3Data]) => {
processInfobar(infobar1Data, 'news-list');
processInfobar(infobar2Data, 'media-list');
processInfobar(infobar3Data, 'teaching-research-list');
})
.catch(error => console.error('Error:', error));/*异常处理*/
</script>
</html>