js根据IP取得天气

<span id="weather"></span>
<script>
function weather(cityName) {
    var charset  = (document.charset || document.characterSet || ‘utf-8‘).toLowerCase() == ‘utf-8‘ ? ‘utf-8‘ : ‘gb2312‘;
    var cityName = cityName ? cityName : ‘‘;
    var oScript  = document.createElement(‘script‘);
    oScript.type = "text/javascript"; oScript.async = true;
    oScript.src  = ‘http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&day=0&city=‘+ cityName +‘&dfc=1&charset=‘+ charset;
    (document.getElementsByTagName(‘head‘)[0] || document.getElementsByTagName(‘body‘)[0]).appendChild(oScript);
    var task     = setInterval(function(){
        if(window.SWther.w != ‘undefined‘) {
            clearInterval(task);
            var city = ‘‘, weatherData = ‘‘, dataInfo = ‘‘;
            for(city in window.SWther.w){
                dataInfo = SWther.w[city][0];
                weatherData = {
                        city : city ,
                        date : SWther.add.now.split(‘ ‘)[0] || ‘‘,
                        day_weather: dataInfo.s1,
                        night_weather :dataInfo.s2,
                        day_temp: dataInfo.t1,
                        night_temp: dataInfo.t2,
                        day_wind:dataInfo.p1,
                        night_wind: dataInfo.p2
                    };
            }
            var w = weatherData.city + ‘ 白天:‘+ weatherData.day_weather + ‘ /‘+ weatherData.day_temp + ‘°C‘ +
                    ‘ 夜晚:‘+ weatherData.night_weather + ‘ /‘+ weatherData.night_temp + ‘°C‘;
            document.getElementById(‘weather‘).innerHTML = w;
        }
    }, 1000);
}
weather();
</script>

 

js根据IP取得天气,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。