www.gusucode.com > 22:【198-3950】景区旅游旅行官方网站类织梦模板(带手机端) > 22:【198-3950】景区旅游旅行官方网站类织梦模板(带手机端)/skin/js/weather.js
var Weather = { weatherData: {}, elments: {}, init: function(code) { this.elments.$wbox = $("#weather"); this.requestWeatherData(code) }, requestWeatherData: function(e) { var t = this; $.ajax({ url: e == "" ? "http://weather.hao.360.cn/sed_api_weather_info.php" : "http://cdn.weather.hao.360.cn/sed_api_weather_info.php", data: { app: "search", code: e }, dataType: "jsonp", jsonp: "_jsonp", success: function(e) { !e.time || t.formatWeatherData(e) } }) }, formatWeatherData: function(e) { var t = this, n = new Date(e.time * 1e3), r = n.getHours(), i = e.weather[0].info, u = new Date(+n), a, f = { time: +n, area: e.area, pm25: "", today: { T: "", img: "", desc: "" }, expires: "" }; e.pm25.pm25 && (f.pm25 = e.pm25.pm25[0]), r >= 5 && r <= 20 ? (a = 1, f.today.T = i.night[2] + "~" + i.day[2], f.today.img = a + "-" + i.day[0], f.today.desc = i.day[1], u.setHours(20, 0, 0)) : (a = 0, f.today.T = i.night[2], f.today.img = a + "-" + i.night[0], f.today.desc = i.night[1], u.setDate(u.getDate() + 1), u.setHours(5, 0, 0)), f.expires = +u, t.weatherData = f, t.fillWeatherData() }, fillWeatherData: function() { var e = this, t = e.weatherData, n = e.elments, r = "http://p0.qhimg.com/d/inn/9371c065/weather/bg-w/", i = [], a = t.pm25, f = "", l = "", h = "", d = "http://www.baidu.com/s?wd=" + encodeURIComponent(t.area[2][0]) + "pm2.5", v, m, g; a != "" ? (a > 200 ? (l = 5, h = "重") : a > 150 ? (l = 4, h = "中") : a > 100 ? (l = 3, h = "轻") : a > 50 ? (l = 2, h = "良") : a >= 0 && (l = 1, h = "优"), f = '<a href="' + d + '" target="_blank">空气质量<b class="pm25-l' + l + '">' + h + "</b></a>") : "", t.area[0][0] == t.area[2][0] ? m = encodeURIComponent(t.area[0][0] + "天气预报") : m = encodeURIComponent(t.area[0][0] + t.area[2][0] + "天气预报"), i = ['<a href="http://www.baidu.com/s?wd=' + m + '" target="_blank"><span>' + t.area[2][0] + '</span><img src="' + r + t.today.img + '.png"><span>' + t.today.desc + t.today.T + '°C</span></a>', f], n.$wbox.html(i.join("")) } }; Weather.init("101300510")