<script type=“text/javascript”>
//动态加载js
function loadJs(jsUrl, fCallBack) {
var _script = document.createElement(‘script’);
_script.setAttribute(‘type’, ‘text/javascript’);
_script.setAttribute(‘src’, jsUrl);
document.getElementByTagName(‘head’)[0].appendChild(_script);
if (typeof fCallBack != ‘undefined’) {
//if (\(.browser.msie) //借助jQuery判断ie </span><span style="color: rgba(0, 128, 0, 1)"> <br></span><span style="color: rgba(0, 0, 0, 1)"> </span><span style="color: rgba(0, 0, 255, 1)">if</span><span style="color: rgba(0, 0, 0, 1)"> (\).browser.msie && (\(.browser.version </span><span style="color: rgba(0, 0, 0, 1)">==</span><span style="color: rgba(0, 0, 0, 1)"> </span><span style="color: rgba(0, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">6.0</span><span style="color: rgba(0, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">) </span><span style="color: rgba(0, 0, 0, 1)">&&</span><span style="color: rgba(0, 0, 0, 1)"> </span><span style="color: rgba(0, 0, 0, 1)">!</span><span style="color: rgba(0, 0, 0, 1)">\).support.style) {
_script.onreadystatechange = function() {
if (this.readyState == ‘loaded’ || this.readyState == ‘complete’) {
fCallBack();
}
};
} else {
_script.onload = function() {
fCallBack();
};
}
}
}
var cityIdUrl = ‘http://61.4.185.48:81/g/’;
var weatherUrl = ‘getWeather.asp?id=’; //因为js的跨域问题,所以通过其他方式拿
/
loadJs(cityIdUrl, function() {
if (typeof id != ‘undefined’) {
var curDayWeather; //先出缓存中获取
$.getJSON(weatherUrl + id, function(data) {
var w_info = data.weatherinfo;
curDayWeather = w_info.weather1;
//下面可以尽情地解析获取到的天气数据
});
}
});/ //为了方便我把它封成回调形式
//演变后:
function getWeather = function(f_cb) {
loadJs(cityIdUrl, function() {
if (typeof id != ‘undefined’) {
var curDayWeather; //可以在此添加缓存机制
//根据不同城市的id获取它的天气预报
$.getJSON(weatherUrl + id, function(data) {
var w_info = data.weatherinfo;
curDayWeather = w_info.weather1; //json对象
//下面可以尽情地解析获取到的天气数据,如果要获取近几天和未来的数据可以在此进行扩展
f_cb(curDayWeather);
});
}
});
}
//调用之
getWeather(function(weather_data) {
//这里把拿到的weather_data放到你想要的位置。
});
</script>
js获取天气预报接口(js获取天气预报接口的方法)
js获取天气预报接口(js获取天气预报接口的方法)lt script type text javascript gt nbsp nbsp nbsp nbsp 动态加载 js nbsp nbsp nbsp function loadJs jsUrl fCallBack nbsp
大家好,我是讯享网,很高兴认识大家。
2025年预训练和自训练(预训练的目的)
上一篇
2025-06-11 16:08
104报文解析工具(104报文类型标识)
下一篇
2025-06-08 09:45

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请联系我们,一经查实,本站将立刻删除。
如需转载请保留出处:https://51itzy.com/kjqy/171678.html