- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果这是显而易见的,我很抱歉,但我只是在编码时进行修补和修改。我正在尝试构建一个天气显示页面,并且已经按照我想要的方式获得了所有内容,但是当天的最高价和最低价似乎停留在创建页面当天的数据上,并且在两天内没有更新。我是否缺少某些内容来获取最新数据?
这是js代码:
if("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
loadWeather(position.coords.latitude + ',' + position.coords.longitude);
});
} else {
loadweather("Danville, KY", "");
}
$(document).ready(function() {
setInterval(getWeather, 60000);
});
function loadWeather(location, woeid) {
$.simpleWeather({
location: location,
woeid: 2389342,
unit: 'f',
success: function(weather) {
city = weather.city;
temp = weather.temp+'°';
wcode = '<img class="weathericon" src="images/weathericons/' + weather.code + '.svg">';
high = '<p>Today\'s High: '+weather.high+'°'+weather.units.temp+'</p>' ;
low = '<p>Today\'s Low: '+weather.low+'° '+weather.units.temp+'</p>';
$(".location").text(city);
$(".temperature").html(temp);
$(".climate_bg").html(wcode);
$(".high").html(high);
$(".low").html(low);
},
error: function(error) {
$(".error").html('<p>' + error + '<p>');
}
});
}
最佳答案
在我看来,您似乎忘记了创建 getWeather
函数。我认为您的前几行代码应该位于其中,因此用此替换 ready
调用之前的所有内容应该可以解决它:
function getWeather() {
if("geolocation" in navigator) {
navigator.geolocation.getCurrentPosition(function(position) {
loadWeather(position.coords.latitude + ',' + position.coords.longitude);
});
} else {
loadweather("Danville, KY", "");
}
}
<小时/>
也就是说,您提供的代码正在成为 The Horror of Implicit Globals 的牺牲品(这是我贫血的小博客上的一篇文章):您想要声明您正在使用的变量(city
、temp
等)在 ajax 回调中使用 var
。
关于javascript - simpleweather.js 中的高温/低温不正确/过时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34359454/
我正在尝试实现 SimpleWeather插入地理定位。我尝试了这段代码,但它只显示按钮。我尝试了没有地理定位的示例,它工作正常,而且我的浏览器与地理定位功能兼容。 我正在 Tomcat 服务器中部署
我一直在搞乱这个插件:http://jsfiddle.net/a4hbL/2064/ 每次满足条件时,我都会尝试使用 JQuery 显示文本:如果外面阳光明媚,则打印“It's Sunny”,如果下雪
我正在 asp.net 页面上使用 SimpleWeather jquery 插件,它工作正常。 https://github.com/monkeecreate/jquery.simpleWeathe
我想在我的网站上使用 simpleweatherjs 显示天气,但这对我不起作用。有人可以告诉我我做错了什么吗?页面是空白的。如果我,例如在 $.simpleWeather({...}); 行之前pu
我正在尝试使用 simpleweather js 制作一个天气应用程序。我已经成功地让应用程序显示我当前位置的天气,但我不确定如何让天气图标显示在温度旁边。任何帮助将不胜感激。这是我的代码笔:http
这个问题在这里已经有了答案: Check if Internet Connection Exists with jQuery? [duplicate] (9 个回答) 关闭 8 年前。
这对我来说非常挑剔,但我想将当前天气状态的大写字母更改为小写。大部分多云到大部分多云。另外我将如何设计文本样式?我以前从未在 jquery 中使用过 html。 html = ' It is curr
我正在使用这个插件:Simple Weather在我的网站上将天气绑定(bind)到我正在构建的简单小部件中。 我需要做的就是显示邮政编码中更深入的位置。目前,如果我在源代码中控制台记录“结果”对象,
我正在使用 weather.js ,我在我的 html 文件中包含了必要的导入: 并放入显示天气的html标签: 稍后我将 javascript: Weather.getCurrent('
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我是一名优秀的程序员,十分优秀!