首页 > 学习笔记 > 根据IP显示单行天气预报
2011
12-13

根据IP显示单行天气预报

////////tianqi.js///////

var getHtml=function(date){
    var len=date.icon.length,html;
    html='';
    if(date.stat){
        html+=' '+date.stat;
    }else{
        html+=' '+date.desc[0];
    }
    html+=' '+date.temp+'';
    return html;
}
var ILData_callback=function(){
    var ID=ILData[4];
    var URL="http://tool.115.com/static/weather/"+ID+".txt";
    getTextWithScript(
        URL,
        function(){
var html=weatherJSON.city[1]+'<span class="WEATHER-DAY">今天</span>'+getHtml(weatherJSON.weather.today,ID)+' <span class="WEATHER-DAY">明天</span>'+getHtml(weatherJSON.weather.tomorrow,ID);
            var JS=document.getElementById("tianqi");
            var OUTER=JS.parentNode;
            var div=document.createElement("span");
            OUTER.replaceChild(div,JS);
            div.id="TOOL_115_COM_JS";
            div.style.fontSize="12px";
            div.style.height="20px";
            div.style.lineHeight="20px";
            div.innerHTML=html;
        }
    );
}
var getTextWithScript=function(url,callback){
    var head = document.getElementsByTagName("head")[0];
    var script = document.createElement("script");
    script.src=url;
    script.onload=script.onreadystatechange=function(){
        if(!this.readyState||this.readyState == "loaded" || this.readyState == "complete"){
            callback();
            script.onload = script.onreadystatechange = null;
            head.removeChild(script);
        }
    }
    head.appendChild(script);
}
window.onload=function(){
    var tool_115_api=document.createElement("script");
    tool_115_api.src='http://tool.115.com/?ct=site&amp;ac=ip_api';
    document.body.appendChild(tool_115_api);
}
调用代码:
<span id="tianqi"></span>
记得在尾部添加:<script type="text/javascript" src="tianqi.js"></script>



最后编辑:
作者:六度
这个人很懒什么也没留!~

发布评论

表情
需要勾选我,才能再发表评论