如何从 html 文档中调用 yahoo weather api javascript 函数
How to call yahoo weather api javascript function from within a html doc
当放置在 html 文档的头部或正文部分时,这些脚本会立即写入文档。如何从文档中的按钮调用它们的功能。我已经尝试了调用 js 函数的所有常用方法,但 none 有效。请帮忙,非常感谢。
<script>
var callbackFunction = function(data1) {
var windy = data1.query.results.channel.wind;
//alert(windy.chill);
document.write("Wind chill factor:" + windy.chill);
};
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
看看这段代码。我得到风寒并将其存储在变量中。然后,我使用按钮的 onclick 属性将该值放入 div。这有帮助吗?
<script>
var wind_chill;
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
wind_chill = wind.chill;
};
function get_wind_chill(){
document.getElementById('wind_chill').innerHTML = "Wind chill factor:" + wind_chill;
}
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
<div id="wind_chill"></div>
<input type="button" onclick="get_wind_chill();" value="Get wind chill" />
注意:这会在页面加载时引起风寒。如果您需要在每次单击按钮时获得新的风冷效果(无需重新加载页面),那么您将需要修改上述代码。
当放置在 html 文档的头部或正文部分时,这些脚本会立即写入文档。如何从文档中的按钮调用它们的功能。我已经尝试了调用 js 函数的所有常用方法,但 none 有效。请帮忙,非常感谢。
<script>
var callbackFunction = function(data1) {
var windy = data1.query.results.channel.wind;
//alert(windy.chill);
document.write("Wind chill factor:" + windy.chill);
};
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
看看这段代码。我得到风寒并将其存储在变量中。然后,我使用按钮的 onclick 属性将该值放入 div。这有帮助吗?
<script>
var wind_chill;
var callbackFunction = function(data) {
var wind = data.query.results.channel.wind;
wind_chill = wind.chill;
};
function get_wind_chill(){
document.getElementById('wind_chill').innerHTML = "Wind chill factor:" + wind_chill;
}
</script>
<script src="https://query.yahooapis.com/v1/public/yql?q=select wind from weather.forecast where woeid in (select woeid from geo.places(1) where text='chicago, il')&format=json&callback=callbackFunction"></script>
<div id="wind_chill"></div>
<input type="button" onclick="get_wind_chill();" value="Get wind chill" />
注意:这会在页面加载时引起风寒。如果您需要在每次单击按钮时获得新的风冷效果(无需重新加载页面),那么您将需要修改上述代码。