第一种方法:
效果如图:
代码:
<!DOCTYPE html>
<html>
<head>
</head>
<title></title>
<body>
<iframe name="weather_inc"
src="http://i.tianqi.com/index.php?c=code&id=7"
style="border:solid 1px #7ec8ea"
width="250" height="100" frameborder="0"
marginwidth="0" marginheight="0" scrolling="no">
</iframe>
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</body>
</html>
第二种方法:
效果如图:
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div class="">{{Weather}}</div>
<script src="https://pv.sohu.com/cityjson?ie=utf-8" type="text/javascript"></script>
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script>
Weather();
function Weather() {
var main = this;
jQuery.support.cors = true;
$.ajax({
url: "http://wthrcdn.etouch.cn/weather_mini",
type: "GET",
dataType: 'json',
data: {city: (returnCitySN.cname).split('省')[1]}, //(returnCitySN.cname).split('省')[1]:获取所在的市
success: function (res) {
//var res=JSON.parse(res);
main.city = res.data.city;//所在城市
var maxTemperature = res.data.forecast[0].high;//最高温度
var minTemperature = res.data.forecast[0].low;//最低温度
var weather = minTemperature.split(' ')[1] + '~' + maxTemperature.split(' ')[1];
var type = res.data.forecast[0].type;//天气状态
main.weather = weather + ' ' + type
console.log(main.city,main.weather);
document.write(main.city,main.weather);
},
error: function (err) {
console.log(err)
}
});
}
</script>
</body>
</html>