-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (79 loc) · 2.03 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>天气查询</title>
<script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/1.11.3/jquery.js"></script>
<script type="text/javascript" src="http://cdn.staticfile.org/artTemplate.js/3.0.1/template.js"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<style type="text/css">
#container1{
height: 400px;
width: 300px;
background-color: #409EF0;
text-align: center;
margin: auto;
padding: 10px;
}
#container2{
font-size: 30px;
color: #FFFFFF;
}
#container3{
color: #FFFFFF;
}
ul{
list-style: none;
text-align: left;
}
#query,#city{
border-radius: 8px;
}
</style>
<script type="text/javascript">
$(document).ready(function(){
$("#query").click(function(){
var city = $("#city").val();
$.ajax({
type: "GET",
url: "http://api.tianapi.com/txapi/tianqi/index",
data: {
key: "MyKey",
city: city
},
success: function(data, status){
console.log(city, data);
var html = template("resultTemp", data);
var container = document.querySelector("#container3");
container.innerHTML = html;
}
});
});
});
</script>
<script type="text/html" id="resultTemp">
<ul>
<li><b>城市</b>:{{newslist[0]["area"]}}</li>
<li><b>日期</b>:{{newslist[0]["date"]}}</li>
<li><b>天气</b>:{{newslist[0]["weather"]}}</li>
<li><b>当前气温</b>:{{newslist[0]["real"]}}</li>
<li><b>最低气温</b>:{{newslist[0]["lowest"]}}</li>
<li><b>最高气温</b>:{{newslist[0]["highest"]}}</li>
<br>
<li><b>生活提示</b>:{{newslist[0]["tips"]}}</li>
</ul>
</script>
</head>
<body>
<div id="container1">
<div id="container2">
全国天气查询
</div>
<hr>
<input type="text" name="city" id="city" placeholder="请输入城市名称">
<button id="query">查询</button>
<div id="container3">
</div>
</div>
</body>
</html>