0
任何幫助與此將不勝感激。我的腳本似乎在Safari中工作,但不適用於任何其他瀏覽器?我很茫然,因爲我是Jquery和解析的新手。謝謝!我的腳本不適用於Chrome和Firefox(Mac),但適用於Safari?
jQuery(document).ready(function($) {
/* Edit these variables */
var api = "66ffde1312******";
var state = "TX";
var city = "Dallas";
$.ajax({
url : "http://api.wunderground.com/api/" + api + "/conditions/q/" + state + "/" + city + ".json",
dataType : "jsonp",
success : function(parsed_json) {
var icon_url_json = "http://icons.wxug.com/i/c/f/" + parsed_json['current_observation']['icon'] + ".gif";
var icon_json = '<img src ="' + icon_url_json + '" />';
var temp_json = parsed_json['current_observation']['temp_f'];
temp_json += "<span>°F</span>";
var condition_json = parsed_json['current_observation']['weather'];
var real_feel_json = "Feels Like " + parsed_json['current_observation']['feelslike_f'] + "°F";
var wind_json = 'Winds are ' + parsed_json['current_observation']['wind_string'];
var location_json = city + ', ' + state;
document.getElementById("weather-icon").innerHTML = icon_json;
document.getElementById("temp").innerHTML = temp_json;
document.getElementById("condition").innerHTML = condition_json;
document.getElementById("real-feel").innerHTML = real_feel_json;
document.getElementById("wind").innerHTML = wind_json;
document.getElementById("location").innerHTML = location_json;
}
});
});
和HTML:
<div class = "weather">
<div id = "weather-icon"></div>
<div class = "text-container">
<p id = "condition"></p>
<p id = "temp"></p>
<p id = "real-feel"></p>
<p id="wind"></p>
<p id="location"></p>
</div>
</div>