网络编程 
首页 > 网络编程 > 浏览文章

利用中国天气预报接口实现简单天气预报

(编辑:jimmy 日期: 2024/10/13 浏览:3 次 )

复制代码 代码如下:
<?php
header("content-type:text/html;charset=utf-8");
$weather = file_get_contents("http://www.weather.com.cn/data/sk/101280601.html");
echo $weather;
?>

复制代码 代码如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gbk" />
<style type="text/css">
.all span {font:bold 30px/50px "宋体";color:red;}
</style>
<title>天气预报</title>
</head>
<body>
<div class="all">
这里是:<span class="place">城市</span>,
气温是<span class="temp">气温</span>,
风向:<span class="wind">风向</span>,
风力:<span class="windPower">风力</span>
</div>
<script type="text/javascript" src="/UploadFiles/2021-04-02/jquery.js"><script type="text/javascript">
$(function () {
$.ajax({
//请求的地址
url : "http://127.0.0.1/weather.php",
//请求成功后执行的函数
success : function (data) {
//用eval()解析返回来的数据,将字符串转成JSON格式
var oD = eval('('+data+')');
//用jquery-1.8.2获取元素
var $place = $(".place"),
$temp = $(".temp"),
$wind = $(".wind"),
$windPower = $(".windPower");
//将返回来的数据放到相应的位置
$place.html(oD["weatherinfo"]["city"]);
$temp.html(oD["weatherinfo"]["temp"] + "°");
$wind.html(oD["weatherinfo"]["WD"]);
$windPower.html(oD["weatherinfo"]["WS"]);
}
});
})
</script>
</body>
</html>

上一篇:php判断手机访问还是电脑访问示例分享
下一篇:php日历制作代码分享
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。