获取新浪天气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 ...
随机推荐
- Java面试题之J2EE是什么
J2EE是Sun公司提出的多层(multi-diered),分布式(distributed),基于组件(component-base)的企业级应用模型(enterpriese application ...
- c++中冒号(:)和双冒号(::)的用法
1.冒号(:)用法 (1)表示机构内位域的定义(即该变量占几个bit空间) typedef struct _XXX{ unsigned ; unsigned char c; } ; XXX (2)构造 ...
- ajax相关
Javascript·部分: <script language="javascript" type="text/javascript" src=" ...
- 已经包含了#include <atlcom.h> #include <comutil.h>还是报错
在WTL工程的.h中 #include <atlbase.h>#include <atlcom.h>#include <atlcomcli.h>#include & ...
- 出现java.lang.NoSuchFieldException resourceEntries错误的解决方法
JSP表单里面的表单输入<input type= "text" name="user">这里面的每一个输入都是一个Attribute,相当于setA ...
- Oracle查看被锁的表和解锁[转]
查看被锁的表 select p.spid,a.serial#, c.object_name,b.session_id,b.oracle_username,b.os_user_name from v$p ...
- WebService之Axis2
写在前面 本文只说Axis2的用法. 1.下载与部署 需要下载两个文件: 下载地址:http://mirrors.cnnic.cn/apache/axis/axis2/java/core/1.7.1/ ...
- 【异常处理】java.lang.NoClassDefFoundError
Exception in thread"main" java.lang.NoClassDefFoundError:org/apache/commons/lang/exception ...
- [问题解决] "Nautilus could not create the required folder "/home/kenneth/.config/nautilus"
错误: "Nautilus could not create the required folder "/home/kenneth/.config/nautilus" 发 ...
- libvirt python binding 变成了一个新项目了。
http://libvirt.org/git/ $ git clone git://libvirt.org/libvirt-python.git 2013年的事情了. $ git show a7a12 ...