>  기사  >  웹 프론트엔드  >  html中嵌入天气预报_html/css_WEB-ITnose

html中嵌入天气预报_html/css_WEB-ITnose

WBOY
WBOY원래의
2016-06-24 11:34:161654검색

先看效果:

html代码:

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 = "html中嵌入天气预报_html/css_WEB-ITnose";
        var day = (new Date().getMonth()+1)+"月"+(new Date().getDate())+"日";
        var tq = "

"+"

"+""+day+""+_w.s1+"

"+"

"+_w.t1 + "℃~" + _w.t2 + "℃"+"

"+"
"+img;
        $('#weather').html(tq);
      }
    });
  });
}
findWeather();

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.