获取新浪天气api显示天气情况(转)
直接上一个html的demo
<!doctype html>
<html class="no-js fixed-layout">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>天气</title>
</head>
<body>
<div class="top-tool">
<span id="sj"></span><span id="weather"><img width="16px" height="16px" src=""></span>
<form action="/Search" method="get" id="qform" class="search-form" style="text-align:right;display:inline;float:right;padding-right:10px;" target="_blank">
<span class="round">
<input name="keywords" id="q" tabindex="1" class="input-key search-q ac_input" value="" maxlength="100" autocomplete="off">
</span> <span class="button">
<input type="submit" tabindex="2" id="su" value="搜 索" class="ui-btn" style="padding: 0px 5px;">
</span>
</form>
</div>
<script type="text/javascript" src="jquery2.1.4.js"></script>
<script type="text/javascript">
function showLocale(objD) {
var str, colorhead, colorfoot;
var yy = objD.getYear();
if (yy < 1900) yy = yy + 1900;
var MM = objD.getMonth() + 1;
if (MM < 10) MM = '0' + MM;
var dd = objD.getDate();
if (dd < 10) dd = '0' + dd;
var hh = objD.getHours();
if (hh < 10) hh = '0' + hh;
var mm = objD.getMinutes();
if (mm < 10) mm = '0' + mm;
var ss = objD.getSeconds();
if (ss < 10) ss = '0' + ss;
var ww = objD.getDay();
if (ww == 0) colorhead = "";
if (ww > 0 && ww < 6) colorhead = "";
if (ww == 6) colorhead = "";
if (ww == 0) ww = "星期日";
if (ww == 1) ww = "星期一";
if (ww == 2) ww = "星期二";
if (ww == 3) ww = "星期三";
if (ww == 4) ww = "星期四";
if (ww == 5) ww = "星期五";
if (ww == 6) ww = "星期六";
colorfoot = ""
str = colorhead + yy + "-" + MM + "-" + dd + " " + hh + ":" + mm + ":" + ss + " " + ww + colorfoot;
return (str);
}
function tick() {
var today;
today = new Date();
document.getElementById("sj").innerHTML = showLocale(today);
window.setTimeout("tick()", 1000);
}
tick(); 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; // 获取城市 citytq = "郑州";
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='16px' height='16px' src='http://i2.sinaimg.cn/dy/main/weather/weatherplugin/wthIco/20_20/" + _f
+ "' />";
var tq = "今日天气 : " + citytq + " " + img + " " + _w.s1 + " " + _w.t1 + "℃~" + _w.t2 + "℃ " + _w.d1 + _w.p1 + "级";
$('#weather').html(tq);
}
});
});
}
findWeather()
</script>
</body>
</html>
别忘记把jquery的库文件替换成本地的
获取新浪天气api显示天气情况(转)的更多相关文章
- 新浪新闻API
新浪新闻API ustcmio 关注 2017.01.15 20:44* 字数 536 阅读 2479评论 2喜欢 7 新浪新闻的API:1.访问手机新浪网https://sina.cn/?from= ...
- 新浪通过API分享 实践
注:如果集成了百度的Frontia和SinaCoreSDK, 那么SSO会出现包冲突 https://github.com/sinaweibosdk/weibo_android_sdk/issues/ ...
- [threeJs][新浪股票api][css3]3D新浪财经数据-最近A股涨的也太疯了......
使用threeJS搭配新浪股票财经API 在线: http://wangxinsheng.herokuapp.com/stock 截图: A股涨幅榜[一片红10%] 检索[单击添加到自选内,自选使用l ...
- 新浪 股票 API
新浪期货数据接口 [例子]http://hq.sinajs.cn/list=M0豆粕连续 M0 返回值如下:var hq_str_M0="豆粕连续,145958,3170,3190,3145 ...
- js获取新浪天气接口
<!doctype html> <html class="no-js fixed-layout"> <head> <meta charse ...
- 免费天气API,天气JSON API,不限次数获取十五天的天气预报
紧急情况说明: 禁用IP列表: 39.104.69.*(原因39.104.69.6 在2018年10月的 17~20日 排行为top 1,每天几十万次.) 47.98.211.* (原因47.98.2 ...
- 调用天气Api实现天气查询
上面是简单截图: 前台代码: @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name=&qu ...
- (转)利用libcurl获取新浪股票接口, ubuntu和openwrt实验成功(三)
1. 利用 CURLOPT_WRITEFUNCTION 设置回调函数, 利用 CURLOPT_WRITEDATA 获取数据指针 官网文档如下 CALLBACK OPTIONS CURLOPT_WRI ...
- 新浪新闻API接口
头条 http://api.sina.cn/sinago/list.json?channel=news_toutiao推荐 http://api.sina.cn/sinago/list.json?ch ...
随机推荐
- 20151203--filter
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Strict//EN" "http://www.w3.org/TR/htm ...
- js工具常用方法
/* function obj$(id) 根据id得到对象 function val$(id) 根据id得到对象的值 function trim(str) 删除左边和右边空格 function ltr ...
- 浅谈C中的指针和数组(五)
前面写了一些C指针和数组的一些知识,但是还有一些很重要的知识没有交代,这里做一个补充. 首先看一下,普通变量(指针也是变量)和数组名查看地址的方式是不同的. 查看数组变量的地址,不需要使用 & ...
- HTML DOM 属性记录
将HTML DOM中几个容易常用的属性做下记录,需要的朋友可以参考下. nodeName.nodeValue 以及 nodeType 包含有关于节点的信息. nodeName 属性含有某个节点 ...
- [MATLAB] 利用遗传算法函数求目标函数的最优解
最近接触到了遗传算法以及利用遗传算法求最优解,所以就把这些相关的内容整理记录一下. 一.遗传算法简介(摘自维基百科) 遗传算法(英语:genetic algorithm (GA))是计算数学中用于解决 ...
- larbin源码之global.h
/** This represent a connection : we have a fixed number of them * fetchOpen links them with servers ...
- 汇编写hello world
.global main main: mov ip, sp stmfd sp!, {fp, ip, lr} sub fp, ip, # ldr r0, =he mov lr, pc b printf ...
- 3.java.lang.ClassNotFoundException
指定的类不存在 这里主要考虑一下类的名称和路径是否正确即可,通常都是程序试图通过字符串来加载某个类时可能引发 异常 比如: 调用Class.forName(); 或者调用ClassLoad的finaS ...
- Windows 7妙用 笔记本变无线AP轻松共享
笔记本变AP的前提和应用原理 笔记本变AP的前提是你所处的房间或地点需要提供有线宽带的连接,而且你的笔记本要有无线网卡.如果这两个条件具备了,即使没有路由器/无线AP等辅助设备,多个笔记本电脑共享上网 ...
- css Block formatting context BFC
w3c关于BFC解释: http://www.w3.org/TR/CSS21/visuren.html#block-formatting Mdn描述: A block formatting conte ...