js实现天气预报模板
jsp天气预报查询课程设计

jsp天气预报查询课程设计一、课程目标知识目标:1. 学生能够理解JSP技术的基本原理和网页开发流程。
2. 学生能够掌握如何在JSP页面中嵌入Java代码,实现动态数据展示。
3. 学生能够学习并运用数据库连接和SQL查询,实现天气预报信息的调用与展示。
4. 学生了解Web服务器的基本配置和使用方法。
技能目标:1. 学生能够运用HTML、CSS和JavaScript等技术,设计并实现具有良好交互性的Web界面。
2. 学生能够通过JSP和Java语言编写程序,实现天气预报的查询和显示功能。
3. 学生能够使用数据库存储和管理数据,实现天气预报信息的更新与维护。
4. 学生能够运用所学知识解决实际项目中遇到的问题,提高项目实践能力。
情感态度价值观目标:1. 学生培养对编程和网络技术的兴趣,提高主动学习和探究的精神。
2. 学生培养团队协作意识,学会在项目开发中与他人沟通与协作。
3. 学生提高问题解决能力,增强自信心,培养勇于克服困难的品质。
4. 学生认识到编程技术在现实生活中的应用价值,激发对科技创新的热情。
课程性质:本课程为信息技术课程,以项目实践为主要教学方式,结合理论讲解,让学生在实际操作中掌握JSP技术。
学生特点:学生具备一定的Java基础,了解Web开发基本概念,但对JSP技术及其在实际项目中的应用尚不熟悉。
教学要求:结合学生特点,注重实践操作,鼓励学生动手实践,培养其编程思维和项目实践能力。
在教学过程中,关注学生个体差异,提供个性化指导,确保每个学生都能在课程中取得进步。
二、教学内容1. JSP技术原理及基本概念:介绍JSP技术的工作原理,理解JSP的生命周期,掌握JSP的内置对象及其作用。
- 相关教材章节:第3章 JSP技术基础2. Web服务器配置与使用:学习如何配置Web服务器,如Tomcat,并了解其基本操作。
- 相关教材章节:第2章 Web服务器与应用服务器3. HTML、CSS和JavaScript基础:复习Web开发基本技术,为后续页面设计打下基础。
基于Swift语言及JSON的天气预报APP的设计与实现

基于Swift语言及JSON的天气预报APP的设计与实现任健(上海信息技术学校,上海200331)摘要:随着大数据时代的来临,各类智能终端在人们的日常生活中发挥着日益重要的作用.本文研究的基于Swift 语言及JSON的天气预报APP是上海信息技术学校信息技术系软件与信息服务专业《程序设计特长(1)》课程的项目教学实例,通过一体化的教学引导学生完成界面设计、天气预报API的使用、JSON数据包的解析等,最终将天气信息呈现给用户。
关键词:Swift;JSON;天气预报;项目教学实例中图分类号:TP311.56文献标识码:A文章编号:1003-9767(2021)05-170-04Design and implementation of weather forecast APP based on Swift languageand JSONREN Jian(Shanghai Information Technology College,Shanghai200331,China)Abstract:With the advent of the Internet+big data era,various smart terminals are playing an increasingly important role in people's daily lives.The weather forecast app based on Swift language and JSON studied in this paper is a project teaching example of the program design specialty(1)course for the Software and Information Service Department of the Information Technology Department of Shanghai Information Technology School.It guides students through integrated plete interface design,use of weather forecast API,analysis of JSON data package,etc.,and finally present weather information to users.Keywords:Swift;JSON;weather forecast;project teaching examples0引言上海信息技术学校的软件与信息服务专业的学制为四年,三年级的学生已经完成了一系列专业课程的学习,具备较好的编码能力。
VB 天气预报源代码

On Error Resume Next
If ph >= 20 Then
ph = ph - 10
Else
ph = 100
End If
SetPh
End Sub
Private Type POINTAPI
X As Long
Y As Long
End Type
Private Declare Function ReleaseCapture Lib "user32" () As Long
Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const HTCAPTION = 2
Private Const WM_NCLBUTTONDOWN = &HA1
Private Const WS_EX_LAYERED As Long = &H80000
Private Const LWA_ALPHA As Long = &H2
SetWindowPos Me.hwnd, -1, 0, 0, 0, 0, 1
riqi.Caption = "今天是:" & Date & GetWeekDay
Me.Height = 5600
IsGetIp = False
微信小程序天气预报开发实例代码源码

微信⼩程序天⽓预报开发实例代码源码微信⼩程序天⽓预报实例主要功能1. ⾃动定位所在城市2. 根据所定位的城市获取天⽓信息3. 显⽰未来⼏天的天⽓情况4. 查看当天天⽓的详情信息先看效果图微信⼩程序-天⽓⾸页微信⼩程序-天⽓详情页思路及编码部份⾃动定位所在城市wx.getLocation:通过官⽅⽂档的API中可以看到wx.getLocation可以获取到当前的地理位置和速度,不过获取到的地理位置只是经纬度,⽽不是真正的城市名称,但我们可以根据这个经纬度来获取城市名称等信息(需要⽤到第三⽅接⼝),再通过城市名称和城市ID获取对应的天⽓信息。
在.js逻辑层增加函数:data:{weatherApikey:'', //天⽓apikey,在 上申请city:'', //城市名称areaid:'', //城市对应的idcurWd:{}, //当天天⽓情况indexs:{}, //当天天⽓详情说明forecast:{} //未来4天的天⽓情况},onLoad:function(options){// ⽣命周期函数--监听页⾯加载this.setData({weatherApikey:getApp().globalData.weatherApikey});this.loadLocation();},//获取当前的位置信息,即经纬度loadLocation: function() {var page = this;wx.getLocation({type: 'gcj02', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可⽤于 wx.openLocation 的坐标success: function(res){// successvar latitude = titude;var longitude = res.longitude;//获取城市page.loadCity(latitude, longitude);}})},//通过经纬度获取城市loadCity: function(latitude, longitude) {var page = this;//这个key是⾃⼰在上申请的var key = "XSWBZ-EVQ3V-UMLPA-U4TP6-6MQFZ-UUFSL";var url = "/ws/geocoder/v1/?location="+latitude+","+longitude+"&key="+key+"&get_poi=1";wx.request({url: url,data: {},method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECT// header: {}, // 设置请求的 headersuccess: function(res){// successvar city = res.data.result.address_component.city;city = city.replace("市", ""); //将“市”去掉,要不然取不了天⽓信息page.setData({city: city});page.loadId(city);}})},//通过城市名称获取城市的唯⼀IDloadId: function(city) {var page = this;var url = "/apistore/weatherservice/citylist";wx.request({url: url,data: {cityname: city},header: {apikey:page.data.weatherApikey},method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECTsuccess: function(res){// successvar cityid = res.data.retData[0].area_id;page.setData({areaid: cityid});page.loadWeather(city, cityid);}})},//通过城市名称和城市ID获取天⽓情况loadWeather: function(city, areaId) {var page = this;var url = "/apistore/weatherservice/recentweathers";wx.request({url: url,data: {cityname:city,cityid: areaId},header: {apikey: page.data.weatherApikey},method: 'GET', // OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE, CONNECTsuccess: function(res){// successpage.setData({curWd : res.data.retData.today, indexs: res.data.retData.today.index, forecast:res.data.retData.forecast});}})},//事件绑定,跳转到天⽓详情页⾯gotoDetail: function(event) {// console.log(this.data.areaid+"==在这⾥跳转=="+this.data.city);wx.navigateTo({url: '../detail/detail?city='+this.data.city+"&cityid="+this.data.areaid})}注意:page.setData或this.setData都是⽤来设置data中的数据值的。
原生JS实现天气预报

原⽣JS实现天⽓预报本⽂实例为⼤家分享了JS实现天⽓预报的具体代码,供⼤家参考,具体内容如下HTML代码<!doctype html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport"content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"><title>Document</title><link rel="stylesheet" href="tianqi.css" ><link rel="stylesheet" href="iconfont/iconfont.css" ></head><body><!-- 搜索 --><div class="search"><span>Tq</span><form target="sou" id="search_from"><input type="search" placeholder="输⼊搜索的城市"><iframe name="sou" style = "display: none"></iframe></form><div class="search-btn"><img src="images/search.png" alt=""></div></div><!-- 历史记录--><div class="history"><div class="la"><span>历史查询</span><img src="images/more.png" alt=""></div><div class="historys"><!-- 历史记录 --></div><div class="clearbtn">清除历史记录</div></div><!-- 今⽇天⽓ --><div class="information"></div><!-- 天⽓预报 --><div class="forecast"></div><!-- ⽣活指数 --><div class="lifestyle"><h2>⽣活指数</h2><div class="lifestyle-box"><div class="lifestyle-item" data-indexs="0"><i class="iconfont icon-shushidu"></i><span>舒适度指数</span></div><div class="lifestyle-item" data-indexs="1"><i class="iconfont icon-3chuanyixiguan"></i><span>穿⾐指数</span></div><div class="lifestyle-item" data-indexs="2"><i class="iconfont icon-ganmaoyaowu"></i><span>感冒指数</span></div><div class="lifestyle-item" data-indexs="3"><i class="iconfont icon-yundong"></i><span>运动指数</span></div><div class="lifestyle-item" data-indexs="4"><i class="iconfont icon-lvyou"></i><span>旅游指数</span></div><div class="lifestyle-item" data-indexs="5"><i class="iconfont icon-iconset0451"></i><span>紫外线指数</span></div><div class="lifestyle-item" data-indexs="6"><i class="iconfont icon-xiche"></i><span>洗车指数</span></div><div class="lifestyle-item" data-indexs="7"><i class="iconfont icon-kongqiwuranfenxi"></i><span>空⽓污染扩散条件指数</span></div></div></div><!-- ⽣活指数弹窗 --><div class="lifestyle-tc"></div><script src="rem.js"></script><script src="Ajax.js"></script><script src="tianqi.js"></script></body></html>CSS代码* {margin: 0;padding: 0;}ul,li {list-style: none;}body {background-size: 120%;color: white;}.search {position: fixed;width: 100%;height: 0.5rem;background-color: rgba(0,0,0,.0);display: flex;justify-content: space-between;align-items: center;}#search_from {width: 2.8rem;height: 0.4rem;position: relative;}.search > span {width: 0.5rem;font-size: 0.25rem;line-height: 0.5rem;text-align: center;font-family: "Segoe UI Symbol";color: white;}.search #search_from > input {width: 2.8rem;height: 0.4rem;border-radius: 0.1rem;text-indent: 0.1rem;outline: none;position: absolute;border: none;border-bottom: 0.01rem solid white;background-color: rgba(255,255,255,.05);color: white;}.search #search_from > input::-webkit-input-placeholder { color: white;}.search > .search-btn {width: 0.5rem;position: relative;}.search > .search-btn > img {width: 0.25rem;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);}.history {height: 0.9rem;overflow: auto;background-color: rgba(255,255,255,.05); transition-duration: 0.5s;}.historys {margin-top: 0.8rem;overflow: hidden;}.history .history-item {display: flex;height: 0.4rem;border-bottom: 0.01rem dashed #cccccc; align-items: center;justify-content: space-evenly;}.history .history-item > .history-time {font-size: 0.14rem;}.history .history-item > .history-city {font-size: 0.18rem;}.history .la {height: 0.3rem;display: flex;position: fixed;top: 0.45rem;width: 90%;background-color: rgba(255,255,255,.0); justify-content: space-between;font-size: 0.16rem;border-bottom: 0.01rem solid white;margin: 0.1rem 0.2rem;font-family: 幼圆;line-height: 0.3rem;}.history .la > span {color: white;}.history .la > img {width: 0.2rem;height: 0.2rem;padding: 0.03rem;border: 0.01rem solid #cccccc;border-radius: 0.05rem;}.clearbtn {height: 0.3rem;text-align: center;text-decoration: underline;font-size: 0.2rem;margin-top: 0.1rem;line-height: 0.3rem;}.information {/*background-color: gold;*/}.now {padding-top: 0.2rem;display: flex;flex-direction: column;}.now .city {font-size: 0.4rem;text-align: center;}.now .situation {padding-top: 0.2rem;display: flex;justify-content: space-evenly;font-size: 0.15rem;align-items: center;}.now .situation > img {width: 1rem;height: 1rem;vertical-align: bottom;}.now .temp {display: flex;flex-direction: column;align-items: center;}.now .temp > h3 {font-size: 0.2rem;margin-top: 0.1rem;}.forecast {background-color: rgba(0,0,0,.3);margin: 0 0.2rem;border-radius: 0.1rem;}.forecast-item {height: 0.3rem;display: flex;justify-content: space-between;margin: 0.1rem 0.2rem 0;padding-top: 0.1rem;}.forecast-item:last-of-type {padding-bottom: 0.1rem;}.forecast-item .forecast-situation > img {width: 0.2rem;height: 0.2rem;}.forecast-item .forecast-situation {font-size: 0.16rem;}.forecast-temp {font-size: 0.18rem;}.lifestyle {display: none;margin: 0 0.2rem;background-color: rgba(0,0,0,.3);border-radius: 0.1rem;}.lifestyle > h2 {text-align: center;margin-top: 0.2rem;font-size: 0.2rem;padding-top: 0.15rem;font-family: 幼圆;}.lifestyle .lifestyle-box {display: flex;flex-wrap: wrap;justify-content: space-between;}.lifestyle .lifestyle-box .lifestyle-item {display: flex;flex-direction: column;width: 0.7rem;height: 0.4rem;font-size: 0.14rem;text-align: center;padding-top: 0.1rem;padding-bottom: 0.05rem;}.lifestyle .lifestyle-box .lifestyle-item > i {font-size: 0.2rem;}.lifestyle .lifestyle-box .lifestyle-item > span {white-space: nowrap;text-overflow:ellipsis;overflow:hidden;}.lifestyle-tc {height: 100vh;position: fixed;top: 0;left: 0;background-color: gold;font-family: 幼圆;line-height: 0.4rem;}.lifestyle-tc .fanghui {width: 0.3rem;height: 0.3rem;position: absolute;left: 0.2rem;top: 0.1rem;}.lifestyle-tc .fanghui > img {width: 100%;}.lifestyle-tc > h2 {font-size: 0.3rem;width: 2.2rem;margin: 0.3rem auto 0;text-align: center;}.lifestyle-tc > span {width: 100%;font-size: 0.2rem;margin-top: 1.5rem;display: block;font-weight: 700;text-indent: 0.16rem;}.lifestyle-tc > p {text-indent: 0.32rem;font-size: 0.2rem;}JS代码let searchtext = document.querySelector('.search #search_from > input');let searchbtn = document.querySelector('.search-btn');let information = document.querySelector('.information'); //当前天⽓divlet forecast = document.querySelector(".forecast"); //获取天⽓预报 divlet lifestyle = document.querySelector('.lifestyle');if (localStorage.tq == undefined) { /*如果默认没搜索过就⾃动搜索普宁*/var tqList = [];let defauleCity = "普宁";autorend(defauleCity);} else { /*如果有搜索记录,就⾃动搜索最后⼀次机城市*/var tqList = JSON.parse(localStorage.tq);let endcityName = tqList[tqList.length - 1].cityName;autorend(endcityName);}/* ⾃动渲染⽅法*/function autorend (cityName) {let nowurl = "https:///s6/weather/now?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b";let dailyurl = "https:///s6/weather/forecast?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b"; let lifestyleurl = "https:///s6/weather/lifestyle?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b"; console.log("执⾏⾃动渲染")rendweather(nowurl,cityName,dailyurl,lifestyleurl);}function getTime() {let date = new Date();let year = date.getFullYear();let month = date.getMonth() + 1;let day = date.getDate();let house = date.getHours();house = house < 10 ? '0' + house : house;let minutes = date.getMinutes();minutes = minutes < 10 ? '0' + minutes : minutes;let second = date.getMinutes();second = second < 10 ? '0' + second : second;let time = year + "年 - " + month + "⽉ - " + day + "⽇ - " + house + ":" + minutes + ":" + second;return time;}/*搜索按钮事件*/searchbtn.addEventListener('click',function () {let time = getTime();let cityName = searchtext.value;/*如果输⼊框不为空才执⾏不加这条件会导致传⼊⼀个空的字符串导致历史记录添加到⼀个空的*/if (cityName != "") {let List = {"cityName" : cityName,"time" : time}tqList.push(List);localStorage.tq = JSON.stringify(tqList);rendhistory(tqList);let nowurl = "https:///s6/weather/now?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b";let dailyurl = "https:///s6/weather/forecast?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b"; let lifestyleurl = "https:///s6/weather/lifestyle?location="+cityName+"&key=26be256aca2c43a7bb7f9a72e0f99a6b"; rendweather(nowurl,cityName,dailyurl,lifestyleurl); /*调⽤渲染⽅法*/searchtext.value = "";}});/*⼿机键盘搜索键事件*/document.getElementById('search_from').onsubmit = function () {searchbtn.click();document.activeElement.blur();}/*主页⾯渲染*/function rendweather (nowurl,cityName,dailyurl,lifestyleurl) {/*获取今⽇天⽓信息*/getAjax(nowurl,function (xhr) {let databoj = JSON.parse(xhr.response);let now = databoj.HeWeather6[0].now;if (now == undefined) { /* 如果获取到的为now 说明⽤户输⼊的城市有误*/if (tqList.length > 1) {//如果长度⼤于1 说明之前⽤户正确输⼊过城市tqList.splice(tqList.length - 1 , 1 ); //执⾏删除最后⼀个元素即输⼊错误的城市rendhistory(tqList); // 执⾏历史记录渲染cityName = tqList[tqList.length - 1].cityName; //将城市名赋值为数组最后⼀个元素即最后⼀次正确搜索的城市} else if (tqList.length == 1) { /* 如果长度为1 说明现在为⽌⽤户没输⼊⼀个正确的城市*/cityName = "普宁"; //将城市名赋值为普宁// tqList.splice(tqList.length - 1 , 1 );tqList.pop(); //删除输⼊错误的⽂字rendhistory(tqList); //执⾏历史记录渲染}autorend(cityName); //最后执⾏⾃动渲染} else { //如果以上都没错误说明⽤户输⼊的城市正确正常执⾏代码/* 渲染今⽇天⽓*/information.innerHTML = `<div class="now"><span class="city">${cityName}</span><div class="situation"><img src="https:///cond_icon/${now.cond_code}.png" alt=""> <!-- 天⽓图标 --><h1 class="text">${now.cond_txt}</h1> <!-- 天⽓状况 --><div class="temp"><h3 class="tmp">温度:${now.tmp}℃</h3> <!-- 温度 --><h3 class="fl">体感温度:${now.fl}℃</h3> <!-- 体感温度 --></div></div>`;/*渲染背景图⽚*/let nowcondtxt = now.cond_code;switch(nowcondtxt) {case "101":case "102":case "103":case "104":document.body.style.backgroundImage = "url('images/2.jpg')";break;case "100":case "200":case "201":case "202":case "203":case "204":document.body.style.backgroundImage = "url('images/1.jpg')"; break;case "205":case "206":case "207":case "208":case "209":document.body.style.backgroundImage = "url('images/7.jpg')"; break;case "210":case "211":case "212":case "213":document.body.style.backgroundImage = "url('images/8.jpg')"; break;case "300":case "301":case "302":case "303":case "304":case "305":case "306":case "307":case "308":case "309":case "310":case "311":case "312":case "313":case "314":case "315":case "316":case "317":case "318":case "399":document.body.style.backgroundImage = "url('images/3.jpg')"; break;case "400":case "401":case "402":case "403":case "404":case "405":case "406":case "407":case "408":document.body.style.backgroundImage = "url('images/4.jpg')"; break;case "500":case "501":case "502":case "503":case "504":case "505":case "506":case "507":case "508":document.body.style.backgroundImage = "url('images/5.jpg')"; break;case "509":case "510":case "511":case "512":case "513":case "514":case "515":document.body.style.backgroundImage = "url('images/6.jpg')"; break;default:document.body.style.backgroundImage = "url('images/9.jpg')";}/*获取天⽓预告信息*/getAjax(dailyurl,function (xhr) {forecast.innerHTML = ""; /*清除之前的渲染*/let databoj = JSON.parse(xhr.response);let daily = databoj.HeWeather6[0].daily_forecast;daily.forEach(function (item,index) {/*如果当天天⽓早上和晚上⼀样就输出⼀个如果不⼀样就早上转晚上(天⽓类型)*/var txt = item.cond_txt_d == item.cond_txt_n ? item.cond_txt_d : item.cond_txt_d + "转" + item.cond_txt_n; let date = '今天'; /*默认今天*/if (index == 1) { /* 第⼆个赋值为明天*/date = "明天";} else if (index == 2) { /* 第三个赋值为后天*/date = "后天";}/*渲染天⽓预报*/forecast.innerHTML += `<div class="nowday forecast-item"><div class="forecast-situation"><img src="https:///cond_icon/${item.cond_code_d}.png" alt="">${date} * <span class="txt">${txt}</span></div><div class="forecast-temp"><span class="max">${item.tmp_max}°/</span><span class="min">${item.tmp_min}°</span></div></div>`;})});lifestyle.style.display = 'block'; /*显⽰⽣活指数模板*//*获取⽣活指数*/getAjax(lifestyleurl,function (xhr) {let databoj = JSON.parse(xhr.response);let lifestyle = databoj.HeWeather6[0].lifestyle;lifestyleclick(lifestyle); /*调⽤⽣活指数渲染⽅法*/});}});}/*⽣活指数渲染⽅法*/let lifestyleitem = document.querySelectorAll('.lifestyle-item');function lifestyleclick (lifestyle) {for (let j = 0; j < lifestyleitem.length; j ++) {lifestyleitem[j].onclick = function () {let index = lifestyleitem[j].dataset.indexs;let li = lifestyle[index];let lifestyletc = document.querySelector('.lifestyle-tc');lifestyletc.innerHTML = `<div class="fanghui"><img src="images/fanghui.png" alt=""></div><h2>${lifestyleitem[j].children[1].childNodes[0].data}</h2><span>${li.brf}</span><p>"${li.txt}"</p>`;lifestyletc.style.display = 'block';/*关闭按钮*/let fanghuibtn = document.querySelector('.fanghui');console.log(fanghuibtn);fanghuibtn.onclick = function () {lifestyletc.style.display = 'none';}}}}//历史记录事件let historys = document.querySelector('.historys');function rendhistory(tqList) {historys.innerHTML = ""; /*每次执⾏历史记录渲染都清除之前的记录防⽌出现重复*/tqList.forEach(function (item,index) {/*将历史记录写⼊*/historys.innerHTML += `<div class="history-item" data-indexs="${index}"><span class="history-time">${item.time}</span><span class="history-city">${item.cityName}</span></div>`;})/*获取历史记录div 添加点击事件* 点击后跳转点击的城市* */let historyitem = document.querySelectorAll('.history-item');for (let j = 0; j < historyitem.length; j ++) {historyitem[j].onclick = function() {let index = historyitem[j].dataset.indexs;let thecityName = tqList[index].cityName;let time = getTime();let List = {"cityName" : thecityName,"time" : time}tqList.push(List);localStorage.tq = JSON.stringify(tqList);rendhistory(tqList);autorend(thecityName);}}}rendhistory(tqList);xiala();//下拉菜单事件function xiala () {let historybtn = document.querySelector('.la > img');let historyDiv = document.querySelector('.history');let clearhistory = document.querySelector('.clearbtn');let flag = true;historybtn.addEventListener('click',function () {if (flag) {flag = false;historybtn.style.backgroundColor = "rgba(0,0,0,.3)";let height = (tqList.length * 0.4) + 1.7;historyDiv.style.height = height + 'rem';} else {flag = true;historybtn.style.backgroundColor = "rgba(0,0,0,.0)";historyDiv.style.height = '0.9rem';}});clearhistory.addEventListener('click',function () { /*清除历史记录事件*/localStorage.removeItem('tq'); /*删除本地存储*/tqList = []; /*将数组清空*/rendhistory(tqList); /*渲染历史记录*/historybtn.click(); /*执⾏下拉按钮点击*/});searchtext.addEventListener('click',function () { //点击输⼊框如果下拉菜单打开就关闭if (!flag) {historybtn.click();}});}以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
留言板与天气预报模块网站开发实训

《网站开发》实训报告题目一天气预报模块题目二留言板模块教学院计算机学院专业班级(一)姓名指导教师2014 年12 月 5 日目录目录------------------------------------------------------------------------------------------------------------------------ 1一概述 ---------------------------------------------------------------------------------------------------------------------- 2一. 天气预报模块 -------------------------------------------------------------------------------------------------- 21.天气预报模块的介绍 ------------------------------------------------------------------------------------- 22.天气预报模块的要求 ------------------------------------------------------------------------------------- 2二.留言板模块 ----------------------------------------------------------------------------------------------------- 31. 留言板模块的介绍 --------------------------------------------------------------------------------------- 32.留言板模块的要求----------------------------------------------------------------------------------------- 3二总体设计 ---------------------------------------------------------------------------------------------------------------- 4一.天气预报模块---------------------------------------------------------------------------------------------------- 41.天气预报模块设计思路 ---------------------------------------------------------------------------------- 42.天气预报模块流程图 ------------------------------------------------------------------------------------- 43.实现方法以及主要技术特点 ---------------------------------------------------------------------------- 64.天气预报模块功能介绍以及我的任务---------------------------------------------------------------- 7二.留言板模块------------------------------------------------------------------------------------------------------- 71.整体思路 ----------------------------------------------------------------------------------------------------- 72.留言板模块流程图----------------------------------------------------------------------------------------- 83.实现方法及主要技术 ------------------------------------------------------------------------------------- 94.主要功能 ----------------------------------------------------------------------------------------------------- 95.我所承担设计部分--------------------------------------------------------------------------------------- 10三详细设计 -------------------------------------------------------------------------------------------------------------- 10一. 天气预报模块 ------------------------------------------------------------------------------------------------ 101.具体功能 --------------------------------------------------------------------------------------------------- 102.重要的实验代码------------------------------------------------------------------------------------------ 103.控件表如下 ------------------------------------------------------------------------------------------------ 154.实验运行截图如下--------------------------------------------------------------------------------------- 15二.留言板模块----------------------------------------------------------------------------------------------------- 15四网站的调试与运行结果说明 ------------------------------------------------------------------------------------- 18一.天气预报模块运行结果说明 ----------------------------------------------------------------------------- 18二.留言板模块结果说明 ---------------------------------------------------------------------------------------- 181.留言板数据库的设计 ----------------------------------------------------------------------------------- 182.网页实现效果--------------------------------------------------------------------------------------------- 19五实训小结 -------------------------------------------------------------------------------------------------------------- 23参考文献------------------------------------------------------------------------------------------------------------------- 24一概述一. 天气预报模块1.天气预报模块的介绍在当今时代天气预报对人类有着及其重要的作用,天气预报的服务手段也变得越来越广泛,而其有效的服务手段有:报刊登载,电台广播,电视播送,天气电话咨询等。
基于Android及JSON的天气预报APP设计与实现

第30卷第1期苏州市职业大学学报V ol.30,No.1 2019年3月Journal of Suzhou V ocational University Mar.,2019DOI:10.16219/ki.szxbzk.2019.01.006基于Android及JSON的天气预报APP设计与实现史桂红(苏州健雄职业技术学院 软件与服务外包学院,江苏 太仓 215400)摘 要:为了方便人们用智能手机查看天气预报信息,在Android平台下设计并实现了天气预报客户端的开发,主要包括天气预报JSON文档的获取与解析、天气预报信息在Android 平台上的呈现等技术,用户通过客户端查询全国城市天气信息和未来天气基本信息。
APP主要功能模块包括城市定位、天气查询及天气显示。
经过测试,结果表明该APP使用方便,完全能满足人们日常对天气信息的需求。
关键词:A ndroid;JSON;JsonFormat;天气预报;Gson中图分类号:TP391 文献标志码:A文章编号:1008-5475(2019)01-0027-06Design and Implementation of Weather Forecast APPBased on Android and JSONSHI Guihong(School of Software and Services Outsourcing,Suzhou Chien-Shiung Institute of Technology,Taicang 215400,China)Abstract:In order to facilitate people’s checking of weather forecast information on smart phones, a weather forecast APP is designed via the Android platform, used for the acquisition and analysis of weather forecast JSON documents and the presentation of weather forecast information on the Android platform and so on. Via the client terminal, its users can request basic weather information nationwide for the time being or to be. Its major functions include urban location module, weather query and display module. The tests results show that the software is easy to use and able to meet people’s needs for weather information.Keywords:Android;JSON;Json Format;weather forecast;Gson天气信息和人们的日常生活息息相关,及时精确地获取天气信息对于人们出行和生活尤为重要,天气预报已经成为人们日常生活不可缺少的一部分。
Java实现天气预报

Java实现天⽓预报通过Java实现天⽓预报,该⽅法必须联⽹import org.apache.http.client.config.RequestConfig;import org.apache.http.client.methods.CloseableHttpResponse;import org.apache.http.client.methods.HttpGet;import org.apache.http.impl.client.CloseableHttpClient;import org.apache.http.impl.client.HttpClientBuilder;import org.apache.http.util.EntityUtils;import java.io.IOException;public class GetWeather {public static String getResult(String url) {try (CloseableHttpClient httpClient = HttpClientBuilder.create().build();CloseableHttpResponse response = httpClient.execute(new HttpGetConfig(url))) {String result = EntityUtils.toString(response.getEntity(),"utf-8"); //设置编码,防⽌乱码return result;} catch (IOException e) {e.printStackTrace();return "";}}}class HttpGetConfig extends HttpGet {public HttpGetConfig(String url) {super(url);setDefaultConfig();}private void setDefaultConfig() {this.setConfig(RequestConfig.custom().setConnectionRequestTimeout(1000 * 10).setConnectTimeout(1000 * 10).setSocketTimeout(1000 * 10).build());this.setHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:92.0) Gecko/20100101 Firefox/92.0"); }}import org.jsoup.Jsoup;import org.jsoup.nodes.Document;import org.jsoup.nodes.Element;import org.jsoup.select.Elements;import java.util.ArrayList;import java.util.LinkedHashMap;import java.util.List;import java.util.Map;public class GetWeatherMain {// public static void main(String[] args) {// GetWeatherMain htmlUtilTest= new GetWeatherMain();// htmlUtilTest.searchWeather("101110200");// }/**** @param* @return获取未来7天的天⽓预报*/public List<Map<String,String>> searchWeather(String id){String result= GetWeather.getResult("/weather/"+id+".shtml");Document document= Jsoup.parse(result);Elements elements;// 获取⽇期和星期elements=document.select("h1");List<String> dateList=new ArrayList<>();List<String> dayList=new ArrayList<>();for (int i = 0; i < 7; i++) {String text=elements.get(i).text();int length=text.length();dateList.add(text.substring(0,length-4));dayList.add(text.substring(length-3,length-1));}//System.out.println(dateList);//System.out.println(dayList);// 获取天⽓elements=document.select("p[class=wea]");List<String> weatherList=new ArrayList<>();for (Element item : elements) {weatherList.add(item.text());}//System.out.println(weatherList);// 获取温度,最⾼温和最低温elements=document.select("p[class=tem]");int i=0;List<String> highTempList=new ArrayList<>();List<String> lowTempList=new ArrayList<>();for (Element item : elements) {highTempList.add(item.select("span").text()+"℃");lowTempList.add(item.select("i").text());}//System.out.println(highTempList);//System.out.println(lowTempList);// 封装结果,每天⼀⾏,未来7天List<Map<String,String>> list=new ArrayList<>();for (int j = 0; j < 7; j++) {Map<String,String> map=new LinkedHashMap<>();map.put("⽇期",dateList.get(j));map.put("day",dayList.get(j));map.put("天⽓",weatherList.get(j));map.put("最⾼温度",highTempList.get(j));map.put("最底温度",lowTempList.get(j));list.add(map);}//list.forEach(System.out::println);return list;}}测试类public static void main(String[] args){String msg = "";GetWeatherMain getWeatherMain = new GetWeatherMain();List<Map<String,String>> list = getWeatherMain.searchWeather("101240101"); //这⾥需要传⼊城市ID,可以通过该链接进⾏查看msg = "【南昌地区天⽓预报】\n"+ list.get(0).toString() +"\n"+ "-----------------------------" + "\n" + list.get(1).toString(); //这⾥只获取两天的天⽓预报 msg = msg.replace('=',':').replace('{',' ').replace('}',' ').replace(',','\n');System.out.println(msg);}。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
JS实现天气预报
将代码复制到html文档中,直接可以出来
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<title>天气预报</title>
</head>
<body>
<iframe name="weather_inc" src="/cframe/2" width="890" height="70" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br/>
<iframe name="weather_inc" src="/cframe/1" width="330" height="35" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br/>
<iframe name="weather_inc" src="/cframe/2" width="890" height="70" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br/>
<iframe name="weather_inc" src="/cframe/9" width="250" height="64" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br/>
<iframe name="weather_inc" src="/cframe/11" width="500" height="15" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=55" style="border:solid 1px #7ec8ea" width="255" height="294" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=8&num=3" width="225" height="80" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=9" width="500" height="60" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=13" width="650" height="221" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=57" width="650" height="427" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<iframe name="weather_inc" src="/index.php?c=code&id=64" width="540" height="291" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
<br />
<br />
<br />
<iframe name="weather_inc" src="/cframe/4" width="130" height="120" frameborder="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>
</body>
</html>。