当前位置:   article > 正文

前端课程设计班级网站之天气预报页面(HTML5+Css3+js+bootstrap+adjx)_天气预报界面网页设计

天气预报界面网页设计
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>天气查询</title>
  8. <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
  9. <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
  10. <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
  11. <!-- <link rel="stylesheet" href="bootstrap/css/bootstrap.min.css"> -->
  12. <style>
  13. .container {
  14. padding-top: 20px;
  15. }
  16. .nav {
  17. padding: 10px 0;
  18. }
  19. .container-fluid {
  20. position: relative;
  21. background-color: skyblue;
  22. width: 1400px;
  23. height: 60px;
  24. top: 10px;
  25. }
  26. #news-list {
  27. position: relative;
  28. top: 15px;
  29. left: 100px;
  30. }
  31. .a0 {
  32. margin: 0 auto;
  33. background: url(img/21.png);
  34. width: 1400px;
  35. height: 2000px;
  36. }
  37. </style>
  38. </head>
  39. <body>
  40. <div class="a0">
  41. <nav class="navbar navbar-default" role="navigation">
  42. <div class="container-fluid">
  43. <div class="navbar-header">
  44. <a class="navbar-brand" href="#">天气查询</a>
  45. </div>
  46. <div>
  47. <ul class="nav navbar-nav">
  48. <li class="active">
  49. <a href="#">软件212</a>
  50. </li>
  51. <li><a href="#">欢迎您</a></li>
  52. <li class="dropdown">
  53. <a href="#" class="dropdown-toggle" data-toggle="dropdown">
  54. 菜单
  55. <b class="caret"></b>
  56. </a>
  57. <ul class="dropdown-menu">
  58. <li><a href="课程设计.html">返回首页</a></li>
  59. <li><a href="教学在线.html">教学在线</a></li>
  60. <li><a href="班级概况.html">班级概况</a></li>
  61. <li class="divider"></li>
  62. <li><a href="留言板2.html">建议评论</a></li>
  63. <li class="divider"></li>
  64. <li><a href="天气预报.html">天气查询</a></li>
  65. </ul>
  66. </li>
  67. </ul>
  68. </div>
  69. </div>
  70. </nav>
  71. <div class="container">
  72. <h1>天气预报</h1>
  73. <div class="form-inline nav">
  74. <div class="form-group">
  75. <input type="text" class="form-control" id="province" placeholder="请输入省份" value="">
  76. </div>
  77. <div class="form-group">
  78. <input type="text" class="form-control" id="city" placeholder="请输入城市" value="">
  79. </div>
  80. <button type="submit" class="btn btn-default" id="btn">搜索</button>
  81. </div>
  82. <table class="table table-striped table-hover" align="center" id="box"></table>
  83. </div>
  84. </div>
  85. </body>
  86. <script src="./js/jsonp.js"></script>
  87. <script src="./js/template-web.js"></script>
  88. <!-- 创建一个模板引擎 -->
  89. <script type="text/html" id="tpl">
  90. <tr>
  91. <th>时间</th>
  92. <th>温度</th>
  93. <th>天气</th>
  94. <th>风向</th>
  95. <th>风力</th>
  96. </tr>
  97. {{each info}}
  98. <tr>
  99. <td>{{date($value.update_time)}}</td>
  100. <td>{{$value.degree}}</td>
  101. <td>{{$value.weather}}</td>
  102. <td>{{$value.wind_direction}}</td>
  103. <td>{{$value.wind_power}}</td>
  104. </tr>
  105. {{/each}}
  106. </script>
  107. <script>
  108. // 获取table容器
  109. var table = document.getElementById('box')
  110. // 获取搜索按钮
  111. var btn = document.getElementById('btn')
  112. // 获取用户输入的省份
  113. var province = document.getElementById('province');
  114. // 获取用户输入的城市
  115. var city = document.getElementById('city');
  116. // 定义dateFormat方法
  117. function dateFormat(data) {
  118. // 获取年,月,日,时,分,秒
  119. var year = data.substr(0, 4)
  120. var month = data.substr(4, 2)
  121. var day = data.substr(6, 2)
  122. var hour = data.substr(8, 2)
  123. var minuter = data.substr(10, 2)
  124. var sec = data.substr(12, 2)
  125. return year + '年' + month + '月' + day + '日 ' + hour + '时' + minuter + '分' + sec + '秒'
  126. }
  127. // 向模板中开放外部变量
  128. // 固定写法template.defaults.import.XX = dateFormat(方法名)
  129. template.defaults.imports.date = dateFormat
  130. // 点击搜索按钮触发事件
  131. btn.onclick = function() {
  132. // 获取用户输入的省份,城市的值
  133. province = province.value;
  134. city = city.value
  135. // 调用jsonp方法
  136. jsonp({
  137. url: 'https://wis.qq.com/weather/common',
  138. data: {
  139. source: 'pc',
  140. weather_type: 'forecast_1h',
  141. province: province,
  142. city: city,
  143. },
  144. success: function(data) {
  145. // 使用模板引擎
  146. var html = template('tpl', {
  147. info: data.data.forecast_1h
  148. })
  149. // 把拼接好的字符串放入table容器中
  150. table.innerHTML = html
  151. }
  152. })
  153. }
  154. </script>
  155. </html>

 

 

本文内容由网友自发贡献,转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号