一、天气系统的完成
1.执行代码
代码如下(示例):
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>北京城市天气</title>
<script src="https://cdn.xxxxx/jquery/1.10.2/jquery.min.js"></script>
<script>
document.addEventListener('plusready', function(){
});
$(document).ready(function() {
$("button").click(function() {
var city = $("#city").val();
$.ajax({
type: "GET", //请求方式
url: "http://wthrcdn.etouch.cn/weather_mini?city="+city,
dataType: "json",
success: function(result){
addBox(result.data.forecast);
}
});
});
});
function addBox(json_data) {
$.each(json_data, function(index, obj) {
$("#box").append("<div'>" +
"<p>" + obj['date'] + "</p>" +
"<p>" + obj['high'] + "</p>" +
"<p>" + obj['fengli'] + "</p>" +
"<p>" + obj['low'] + "</p>" +
"<p>" + obj['fengxiang'] + "</p>" +
"<p>" + obj['type'] + "</p>" +
"</div>");
});
}
</script>
</head>
<body>
<div>
<h3>请输入城市:</h3>
城市:<input type="text" id="city"/>
<br>
<button type="button">提交</button>
</div>
<br>
<div id="box"></div>
</body>
</html>