赞
踩
- <!DOCTYPE html>
- <html lang="en">
-
- <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 rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
- <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
- <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
- <!-- <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> -->
- <style>
- .container {
- padding-top: 20px;
- }
-
- .nav {
- padding: 10px 0;
- }
-
- .container-fluid {
- position: relative;
- background-color: skyblue;
- width: 1400px;
- height: 60px;
- top: 10px;
- }
-
- #news-list {
- position: relative;
- top: 15px;
- left: 100px;
- }
-
- .a0 {
- margin: 0 auto;
- background: url(img/21.png);
- width: 1400px;
- height: 2000px;
- }
- </style>
- </head>
-
- <body>
- <div class="a0">
- <nav class="navbar navbar-default" role="navigation">
- <div class="container-fluid">
- <div class="navbar-header">
- <a class="navbar-brand" href="#">天气查询</a>
- </div>
- <div>
- <ul class="nav navbar-nav">
- <li class="active">
- <a href="#">软件212班</a>
- </li>
- <li><a href="#">欢迎您</a></li>
- <li class="dropdown">
- <a href="#" class="dropdown-toggle" data-toggle="dropdown">
- 菜单
- <b class="caret"></b>
- </a>
- <ul class="dropdown-menu">
- <li><a href="课程设计.html">返回首页</a></li>
- <li><a href="教学在线.html">教学在线</a></li>
- <li><a href="班级概况.html">班级概况</a></li>
- <li class="divider"></li>
- <li><a href="留言板2.html">建议评论</a></li>
- <li class="divider"></li>
- <li><a href="天气预报.html">天气查询</a></li>
- </ul>
- </li>
- </ul>
- </div>
- </div>
- </nav>
- <div class="container">
- <h1>天气预报</h1>
- <div class="form-inline nav">
- <div class="form-group">
- <input type="text" class="form-control" id="province" placeholder="请输入省份" value="">
- </div>
- <div class="form-group">
- <input type="text" class="form-control" id="city" placeholder="请输入城市" value="">
- </div>
- <button type="submit" class="btn btn-default" id="btn">搜索</button>
- </div>
-
- <table class="table table-striped table-hover" align="center" id="box"></table>
- </div>
- </div>
- </body>
-
- <script src="./js/jsonp.js"></script>
- <script src="./js/template-web.js"></script>
-
- <!-- 创建一个模板引擎 -->
- <script type="text/html" id="tpl">
- <tr>
- <th>时间</th>
- <th>温度</th>
- <th>天气</th>
- <th>风向</th>
- <th>风力</th>
- </tr>
-
- {{each info}}
- <tr>
- <td>{{date($value.update_time)}}</td>
- <td>{{$value.degree}}</td>
- <td>{{$value.weather}}</td>
- <td>{{$value.wind_direction}}</td>
- <td>{{$value.wind_power}}</td>
- </tr>
- {{/each}}
-
- </script>
-
- <script>
- // 获取table容器
- var table = document.getElementById('box')
-
- // 获取搜索按钮
- var btn = document.getElementById('btn')
-
- // 获取用户输入的省份
- var province = document.getElementById('province');
-
- // 获取用户输入的城市
- var city = document.getElementById('city');
-
- // 定义dateFormat方法
- function dateFormat(data) {
- // 获取年,月,日,时,分,秒
- var year = data.substr(0, 4)
- var month = data.substr(4, 2)
- var day = data.substr(6, 2)
- var hour = data.substr(8, 2)
- var minuter = data.substr(10, 2)
- var sec = data.substr(12, 2)
- return year + '年' + month + '月' + day + '日 ' + hour + '时' + minuter + '分' + sec + '秒'
- }
-
- // 向模板中开放外部变量
- // 固定写法template.defaults.import.XX = dateFormat(方法名)
- template.defaults.imports.date = dateFormat
-
- // 点击搜索按钮触发事件
- btn.onclick = function() {
- // 获取用户输入的省份,城市的值
- province = province.value;
- city = city.value
-
- // 调用jsonp方法
- jsonp({
- url: 'https://wis.qq.com/weather/common',
- data: {
- source: 'pc',
- weather_type: 'forecast_1h',
- province: province,
- city: city,
- },
- success: function(data) {
- // 使用模板引擎
- var html = template('tpl', {
- info: data.data.forecast_1h
- })
- // 把拼接好的字符串放入table容器中
- table.innerHTML = html
- }
- })
- }
- </script>
-
- </html>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。