【问题标题】:My Script is not working in Chrome and Firefox (Mac) but works in Safari?我的脚本在 Chrome 和 Firefox (Mac) 中不起作用,但在 Safari 中起作用?
【发布时间】:2014-04-03 03:05:50
【问题描述】:

对此的任何帮助将不胜感激。我的脚本似乎可以在 Safari 中运行,但不能在任何其他浏览器上运行?我很茫然,因为我对 Jquery 和解析非常陌生。谢谢!

    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>

【问题讨论】:

    标签: javascript jquery json cross-browser


    【解决方案1】:

    最好的方法是在 Chrome 中调试并找出它在哪一行被破坏。在 chrome 上,您可以按 F12 在控制台中查看错误。在此之前,可以尝试注释掉天气图标 div 设置内部 html,这对我来说似乎有点奇怪。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-20
      • 1970-01-01
      • 2013-01-04
      相关资源
      最近更新 更多