获取新浪天气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 ...
随机推荐
- MVC5 Controller简要创建过程(1):ControllerFactory的创建
即将离职,闲来无事回顾下MVC的源码,到了Controller创建这里,由于流程有点复杂,鉴于自己记性不太好,索性就记录一下吧,方便日后参照. 首先看MvcHandler: public class ...
- setter设置器 gutter访问器
set方法书写规范: 1.必须以set开头,set后跟去掉下划线的实例变量并且首字母大写.ps: setAge:2.一定有参数3.不能有返回值4.一定是对象方法(-开头)5.形参一般是去掉下划线的实例 ...
- L6 Shell
写出以下shell脚本1 判定一个用参数指定的文件是否为可执行,如果不是,则改为可执行#!/bin/bash if [ -x $1 ]then echo "OK"else echo ...
- 动态sql构建的过程
基本原理:使用xsqlbuilder框架完成动态sql的构建. 基本流程:使用WebUtils.getParametersStartingWith(ServletActionContext.getRe ...
- javascript 学习笔记(权威指南)
1.数组的sort()方法默认是按照字母排序的,下面举个栗子说明: 1)全是字母: var arr =["zu","fan","an",&q ...
- firefox 自写底层扩展,源码简介
还记得2010年的时候,那时候开始喜欢上了js,经常逛MDN 一开始写些简单的油猴脚本,慢慢的接触了扩展开发,发现用自己的js知识 加上firefox的插件API,可以完成好多功能. 看了很多插件的源 ...
- zookeeper参考
ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,它是一个为分布式应用提供一致性服务的软件,提供的功能包括:配置维护.名字服务.分布式同步.组服务等. 我需要运行几个 ...
- 一个由proguard与fastJson引起的血案
更多内容在这里查看 https://ahangchen.gitbooks.io/windy-afternoon/content/ 更新微信sdk导致ComposeData中的内部类ComposeDat ...
- ubuntu15.04下编译 libvirt
很久没有编译 libvirt了. 工作需要,重新编译. [org_ref]: http://libvirt.org/compiling.html 很简单. 编译过程, 还是很多问题. 依赖包(给懒人参 ...
- pwd显示链接文件的真实路径
1.pwd用于显示当前工作路径 2.pwd -P 用于显示当前的实际工作路径(主要用于链接文件) 加参数难以了理解,看个例子就明白了: 进入链接文件,pwd显示的是链接文件所在的路径,而你不是链接文件 ...