-
Notifications
You must be signed in to change notification settings - Fork 0
/
新闻卡片 copy.html
89 lines (77 loc) · 1.94 KB
/
新闻卡片 copy.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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Card Example</title>
<style>
.card {
display: flex;
flex-direction: column;
align-items: center;
width: 480px;
height: 480px;
border: 1px solid #ccc;
border-radius: 15px;
padding: 20px;
background-image: linear-gradient(0deg, #a8edea 0%, #fed6e3 100%)
}
.title {
font-size: 24px;
font-weight: bold;
margin-bottom: 10px;
}
.content {
font-size: 16px;
margin-bottom: 20px;
}
.image {
width: 100%;
height: 200px;
object-fit: cover;
margin-bottom: 20px;
}
</style>
</head>
<body>
<div class="card">
<img class="image" src="" alt="">
<h2 class="title">标题</h2>
<p class="content"></p>
<p class="source"></p>
<p class="time"></p>
</div>
<script>
var json = `{
"book": {
"name": "Harry Potter and the Goblet of Fire",
"author": "J. K. Rowling",
"year": 2000,
"characters": ["Harry Potter", "Hermione Granger", "Ron Weasley"],
"genre": "Fantasy Fiction",
"price": {
"paperback": "$10.40", "hardcover": "$20.32", "kindle": "$4.11"
}
}
}`;
// 将 JSON 数据转换为 JSON 对象
var obj = JSON.parse(json);
// 打印嵌套的 JSON 数据
function printValues(obj) {
for (var k in obj) {
if (obj[k] instanceof Object) {
printValues(obj[k]);
} else {
document.write(obj[k] + "<br>");
};
}
};
// 调用 printValues() 函数
printValues(obj);
document.write("<hr>");
// 打印 JSON 数据中的单个值
document.write(obj["book"]["author"] + "<br>"); // 输出: J. K. Rowling
document.write(obj["book"]["characters"][0] + "<br>"); // 输出: Harry Potter
document.write(obj["book"]["price"]["hardcover"]); // 输出: $20.32
</script>
</body>
</html>