我使用一段Javascript在仪表板上显示当前天气。该函数以“inpage”格式写入,因此需要将它放在我的index.php中。我想将该函数移动到我的scripts.js,但是如何将此代码转换为正常工作?我对Javascript函数很新...有什么想法吗?
reallySimpleWeather.weather({
wunderkey: '', // leave blank for Yahoo
location: 'Holten, NL', //your location
woeid: '', // "Where on Earth ID"
unit: 'c', // 'c' also works
success: function(weather) {
html = '<div id="weergraden">'+weather.temp+'°'+' graden</div>';
html += '<div id="weerstatus">'+weather.currently.replace("Mostly ", "Veelal ").replace("Showers" , "Regenbuien").replace("Sunny", "Zonnig").replace("Partly ", "Lichte ").replace("Cloudy", "Bewolking").replace("Rain", "Regen").replace("Scattered " , "Verspreide ").replace("Clear", "Helder")+'</div>';
html += '<img src="'+weather.image+'"></img>';
//html += "<img src='"+serverurl+"weer/"+weather.currently.replace(" ", "_")+".png'></img>";
document.getElementById('weer').innerHTML = html;
setInterval(weather, 6000);
},
error: function(error) {
document.getElementById('weer').innerHTML = '<p>'+error+'</p>';
}
});
答案 0 :(得分:0)
您可以将此代码复制到单独的文件中,例如app.js, 然后将其连接到您的php页面。
<?php echo"<script language='javascript' src='reallySimpleWeatherCDN'></script>";?>
<?php echo"<script language='javascript' src=/javascript/app.js></script>";?>
请考虑在reallySimpleWeather库之后连接app.js