获取新浪天气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 ...
随机推荐
- MSSQL查询连接数
SELECT * FROM [Master].[dbo].[SYSPROCESSES] WHERE [DBID] IN ( SELECT [DBID] FROM [Master].[dbo].[SYS ...
- SessionState的配置 [转载]
ASP.NET会话状态模块在Web.config文件中<System.web>标记下的<Sessionstate>标记的mode属性来决定该属性的四种可能的值: Off. In ...
- Oracle EBS使用adpatch工具打patch过程【Z】
Oracle EBS使用adpatch工具打patch过程 从Metalink下载补丁 登陆到Metalink(https://support.oracle.com),Oracle内部用户可以使用AR ...
- [C++空间分配]new运算符、operator new、placement new的区别于联系
先科普一下: 1. new的执行过程: (1)通过operator new申请内存 (2)使用placement new调用构造函数(内置类型忽略此步) (3)返回内存指针 2. new和malloc ...
- QF——UI之几种常用的隐藏键盘的方法
怎么在填写完UITextField之后,点击空白处,隐藏软键盘. 下面两个方法都可以隐藏键盘 [tf resignFirstResponder]; 停止textfield的第一响应者 [self.vi ...
- Java学习之道:Java项目打包发布
Java项目打包发布 如果只想发布为一个可执行的jar包,使用eclipse的Export功能就可以了 使用eclipse的Export功能,将项目中的所有package打包为一个pet.jar文件, ...
- php中date函数获取当前时间的时区误差解决办法
例:echo date('Y-m-d H:i:s', time()); 输出时间:2008-10-12 02:32:17 但实际时间是:2008-10-12 10:32:17时间误差8个小时 PHP手 ...
- jquery的$().each,$.each的区别与应用
在jquery中,遍历对象和数组,经常会用到$().each和$.each(),两个方法.两个方法是有区别的,从而这两个方法在针对不同的操作上,显示了各自的特点. $().each,对于这个方法,在d ...
- MyEclipse数据库反向生成实体类
MyEclipse数据库反向生成实体类 “计应134(实验班) 凌豪” 当我们在开发项目涉及到的表太多时,一个一个的写JAVA实体类很是费事.然而强大的MyEclipse为我们提供简便的方法:数据库反 ...
- 走进C标准库(4)——"stdio.h"中的putc
花了点时间把园子弄得好看了点,现在继续. 函数名: putc 功 能: 输出一字符到指定流中 用 法: int putc(int ch, FILE *stream); #define _putc_ ...