0
我正在使用JSFiddle example - 我將CSS,JavaScript和HTML放在一個文件中,並且正在使用WampServer來運行它。沒有顯示天氣信息。我仔細檢查了一切,但找不到問題。有什麼建議麼?JavaScript無法顯示天氣
代碼:
<!DOCTYPE html>
<html>
<head>
<style>
.weatherModule {
background:#f2f2f2;
height:150px;
width:250px;
border: 1px dashed #ccc;
padding: 1em;
}
.currentConditions {
float: left;
}
.weatherModule {
padding: 1em;
}
.currentIcon {
float: left;
margin: 0 .75em;
}
</style>
<script type="text/javascript">
displayWeather(){
$.ajax
url: 'http://api.wunderground.com/api/36b799dc821d5836/conditions/q/PA/Horsham.json'
dataType: 'jsonp'
data: 'url'
success: (data) ->
for index, result of data
temp = Math.round result.temp_f
icon = result.icon_url
weather = result.weather
$('p.currentConditions').html "Currently #{temp} ° F and #{weather}"
$('div.currentIcon').html "<img src='#{icon}' >"
}
</script>
</head>
<body>
<div class="weatherModule">
<p class="currentConditions"></p>
<div class="currentIcon"></div>
</div>
<form>
<button type="button" onclick="displayWeather()">Display Weather</button>
</form>
</body>
</html>
你的小提琴適合我。 – Sumurai8
'$ .ajax({[parameters]});' –
Javascript控制檯中的任何錯誤? – Barmar