色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

利用中國天氣預報接口實現簡單天氣預報

復制代碼 代碼如下:
<?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="http://127.0.0.1/jquery.js"></script>
<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技術利用中國天氣預報接口實現簡單天氣預報,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 西昌市| 大理市| 淮北市| 静安区| 揭阳市| 海门市| 塔河县| 沁源县| 南靖县| 五华县| 巴楚县| 安陆市| 南昌市| 绥阳县| 邹城市| 报价| 保康县| 台东市| 涪陵区| 景谷| 宁陵县| 山阳县| 周口市| 永嘉县| 新野县| 瑞丽市| 章丘市| 龙海市| 连山| 色达县| 吉首市| 蒙城县| 张家川| 儋州市| 乐东| 黄浦区| 普宁市| 屏东县| 新营市| 兰西县| 乌海市|