////////tianqi.js///////
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
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&ac=ip_api’; document.body.appendChild(tool_115_api); } |
调用代码:
<span id="tianqi"></span>
记得在尾部添加:<script type="text/javascript" src="tianqi.js"></script>
文章评论