首先,我不知道 javascript/jquery...仍在努力学习。我目前正在开发一个使用 SimpleWeather.js 在网页上显示天气的项目。但是,我希望结果(即位置、温度、高/低等)显示在页面的不同位置。例如,我希望位置显示在窗口的左上角,而当前温度显示在左中,在单独的 div 中。不幸的是,我似乎无法将结果分开:它们都加载在一起并且不能放入单独的 div 中。
我的页面设置如下:
<body>
<div id="container">
<div id="top-header">
<h1 id="display-location">Location Here...</h1>
</div>
</div>
<div id="main-body">
<div id="current-weather-column">
<h2>Current weather is gonna go here.</h2>
</div>
</div>
<div id="four-day-forecast-area" class="three-col">
<h2>Rest of forecast/four-day forecast here...</h2>
</div>
<script>
// Docs at http://simpleweatherjs.com
$(document).ready(function() {
$.simpleWeather({
zipcode: '60605',
woeid: '', //2357536
location: '',
unit: 'f',
success: function(weather) {
if(weather.temp > 75) {
$('body').animate({backgroundColor: '#F7AC57'}, 1500);
} else {
$('body').animate({backgroundColor: '#0091c2'}, 1500);
}
html = '<h1 class="icon-'+weather.code+'"></h1>';
html += '<h2 class="weather-temp">'+weather.temp+'°</h2>';
html += '<ul><li>'+weather.city+', '+weather.region+'</li>';
html += '<li class="currently">'+weather.currently+'</li></ul>';
//html += '<li>'+weather.tempAlt+'°C</li></ul>';
var timestamp = moment(weather.updated);
html += '<p class="updated">Updated '+moment(timestamp).fromNow()+'</p>';
$("#weather").html(html);
},
error: function(error) {
$("#weather").html('<p>'+error+'</p>');
}
});
});
<!-- I then list the rest of the script which is fairly long. If needed, you can take a look at http://simpleweatherjs.com -->
</body>
希望这是有道理的。你们能给予的任何帮助对我来说意义重大。谢谢!