如何从 html 文档中调用 yahoo weather api javascript 函数
How to call yahoo weather api javascript function from within a html doc
当放置在html文档的头部或正文部分时,这些脚本会立即写入文档。如何从文档中的按钮调用它们的功能。我已经尝试了调用js函数的所有常用方法,但没有一种有效。请帮忙,非常感谢。
<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" />
注意:页面加载时,这会产生寒意。如果你需要在每次点击按钮时获得新的风寒(不做页面重新加载),那么你将需要修改上面的代码。
相关文章:
- 如何使用jquery解析具有相同标签名称的yahoo天气api数据
- 向Yahoo Finance API发出JSONP请求时获得400错误请求
- 如何在yahoo weather中将变量分配到javascript src脚本中
- 如何从 html 文档中调用 yahoo weather api javascript 函数
- 如何将 JavaScript Yahoo Weather API 调用属性替换为变量
- 带有jQuery和YQL的Weather突然停止工作
- 使用Javascript、Jquery或Ajax动态插入Yahoo Merchant Store目录标签
- Yahoo - OAuth2 - SocialAPI:在初始响应中不返回“Access-Control-Allow-Or
- 计算外部网页上的HTML元素,例如 msn.com,yahoo.com
- 通过Yahoo API YQL- Javascript获取JSONP数据
- Yahoo api 从公共数据 JavaScript 切换到 oAuth
- Yahoo Pipes RSS pubDate在通过Google Feeds API查看时显示为“未定义”
- 使用 Yahoo API 拖放带有链接锚点的容器
- Yahoo Ticker API不再是实时的
- 带有 gFlags 的 Yahoo YQL 查询不返回任何内容
- Yahoo YUI library CustomEvent class - subscribe() and fire()
- 使用JavaScript实现Yahoo oauth和api
- 查找非封闭的XML节点(Yahoo天气)
- Yahoo fluxible"shell未定义“;在Windows上
- AJAX解析+Yahoo YQL未返回任何结果