zoukankan      html  css  js  c++  java
  • html中嵌入天气预报

    先看效果:

    html代码:

    <div id="weather"></div>

    js代码:

    function findWeather() {
      var cityUrl = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js';
      $.getScript(cityUrl, function(script, textStatus, jqXHR) {
        var citytq = remote_ip_info.city ;// 获取城市
        var url = "http://php.weather.sina.com.cn/iframe/index/w_cl.php?code=js&city=" + citytq + "&day=0&dfc=3";
        $.ajax({
          url : url,
          dataType : "script",
          scriptCharset : "gbk",
          success : function(data) {
            var _w = window.SWther.w[citytq][0];

            var _f= _w.f1+"_0.png";
            if(new Date().getHours() > 17){
              _f= _w.f2+"_1.png";
            }
            var img = "<img width='40px' height='40px' style=' margin-left:20px'src='http://php.weather.sina.com.cn/images/yb3/78_78/" +_f+ "' />";
            var day = (new Date().getMonth()+1)+"月"+(new Date().getDate())+"日";
            var tq = "<div style='float:left'>"+"<p>"+"<span>"+day+"</span>"+_w.s1+"</p>"+"<p>"+_w.t1 + "℃~" + _w.t2 + "℃"+"</p>"+"</div>"+img;
            $('#weather').html(tq);
          }
        });
      });
    }
    findWeather();

  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    第十四周助教总结
    C语言I博客作业07
    第十三周助教总结
    C语言I博客作业06
    第十二周助教总结
    学期总结
    C语言I博客作业09
    C语言I博客作业08
  • 原文地址:https://www.cnblogs.com/chenrunlin/p/4935172.html
Copyright © 2011-2022 走看看