我想通过 yahoo 的 API 获取天气。函数触发直到html
. 我把alert
html 放在 function 之前。在它html
向我显示警报之前。但是当它之后html
它不起作用。它显示html
有错误。什么问题?
<script type="text/javascript">
$(document).ready(function () {
$.simpleWeather({
zipcode: '',
woeid: '@Html.DisplayFor(modelItem => item.zipcode)',
location: '',
unit: 'c',
success: function (weather) {
//html = '<h2>' + weather.city + ', ' + weather.region + '</h2>';
//html += '<img style="float:left;" width="125px" src="' + weather.image + '">';
alert("hi");
html += '<p>' + weather.temp + '° ' + weather.units.temp + '<br /><span>' + weather.currently + '</span></p>';
html += '<a href="' + weather.link + '">View Forecast »</a>';
$("#weather").html(html);
},
error: function (error) {
$("#weather").html('<p>' + error + '</p>');
}
});
});
</script>
现在警报有效
但在此警报中不起作用:
<script type="text/javascript">
$(document).ready(function () {
$.simpleWeather({
zipcode: '',
woeid: '@Html.DisplayFor(modelItem => item.zipcode)',
location: '',
unit: 'c',
success: function (weather) {
html = '<h2>' + weather.city + ', ' + weather.region + '</h2>';
html += '<img style="float:left;" width="125px" src="' + weather.image + '">';
alert("hi");
html += '<p>' + weather.temp + '° ' + weather.units.temp + '<br /><span>' + weather.currently + '</span></p>';
html += '<a href="' + weather.link + '">View Forecast »</a>';
$("#weather").html(html);
},
error: function (error) {
$("#weather").html('<p>' + error + '</p>');
}
});
});
</script>
这是我的 html 代码:
<div id="weather"></div>
html
有错误。请帮帮我 。