Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30479086
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: 系统运维

2012-07-18 21:43:19


点击(此处)折叠或打开

  1. <!DocType html>
  2. <html>
  3. <head>
  4. <br>
  5. <meta charset="utf-8">
  6. <script type="text/javascript" src="">
  7. </script><script type="text/javascript">
  8.   google.load("search", "1");
  9.   google.load("jquery", "1.4.2");
  10.   google.load("jqueryui", "1.7.2");
  11. </script>
  12. <script type="text/javascript">
  13. function loadXMLDoc(url) {
  14.     $.get(url// + '&t=' + Math.random()
  15.     ,

  16.     function (data, textStatus){
  17.     
  18.         $('#weather').html('');
  19.         
  20.         var weather = data.getElementsByTagName("weather")[0];
  21.         var forecast_information = weather.getElementsByTagName("forecast_information")[0];
  22.         var citytag = forecast_information.getElementsByTagName("city")[0];
  23.         var city = citytag.getAttribute("data");
  24.         $('#city').html(city);
  25.         
  26.         var current_conditions = weather.getElementsByTagName("current_conditions")[0];
  27.         
  28.         var conditiontag = current_conditions.getElementsByTagName("condition")[0];
  29.         var condition = conditiontag.getAttribute("data");
  30.         $('#condition').html(condition);
  31.         
  32.         var temp_ctag = current_conditions.getElementsByTagName("temp_c")[0];
  33.         var temp_c = temp_ctag.getAttribute("data");
  34.         $('#temp_c').html('温度: ' + temp_c);
  35.         
  36.         var humiditytag = current_conditions.getElementsByTagName("humidity")[0];
  37.         var humidity = humiditytag.getAttribute("data");
  38.         $('#humidity').html(humidity);
  39.         
  40.         var wind_conditiontag = current_conditions.getElementsByTagName("wind_condition")[0];
  41.         var wind_condition = wind_conditiontag.getAttribute("data");
  42.         $('#wind_condition').html(wind_condition);
  43.         
  44.         
  45.         var forecast_conditions = weather.getElementsByTagName("forecast_conditions");
  46.         var forecast_conditions_txt = '';
  47.             forecast_conditions_txt += '
  48. ';
  49.         var i = 0;
  50.         for (i = 0;i < forecast_conditions.length; i++) {
  51.             var day_of_weektag = forecast_conditions[i].getElementsByTagName("day_of_week")[0];
  52.             var day_of_week = day_of_weektag.getAttribute("data");
  53.             var lowtag = forecast_conditions[i].getElementsByTagName("low")[0];
  54.             var low = lowtag.getAttribute("data");
  55.             var hightag = forecast_conditions[i].getElementsByTagName("high")[0];
  56.             var high = hightag.getAttribute("data");
  57.             var icontag = forecast_conditions[i].getElementsByTagName("icon")[0];
  58.             var icon = "" + icontag.getAttribute("data");
  59.             var conditiontag = forecast_conditions[i].getElementsByTagName("condition")[0];
  60.             var condition = conditiontag.getAttribute("data");
  61.             forecast_conditions_txt += '
  62. ';
  63.         }
  64.         forecast_conditions_txt += '
  65. 日期低温高温天气
    ' + day_of_week + '' + low + '' + high + '' + condition + '+ icon + '" />
    '
    ;
  66.         $('#weather').html(forecast_conditions_txt);
  67.     });
  68. }
  69. </script>
  70. </br>
  71. </head>
  72. <body onload="loadXMLDoc('/ig/api?hl=zh-cn&weather=Dalian')">
  73. <p id="city"></p>
  74. <p id="condition"></p>
  75. <p id="temp_c"></p>
  76. <p id="humidity"></p>
  77. <p id="wind_condition"></p>
  78. <div id="weather">
  79. </div>
  80. <button onclick="loadXMLDoc('/ig/api?hl=zh-cn&weather=Dalian')">更新</button>

  81. </body>
  82. </html>

阅读(2237) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~