【问题标题】:jQuery working in Chrome and Safari, but not Firefox or IE?jQuery 在 Chrome 和 Safari 中工作,但不是 Firefox 或 IE?
【发布时间】:2013-10-18 10:53:04
【问题描述】:

我对我编写的一些 JavaScript/jQuery 代码感到很困惑,我在 Webkit 浏览器(Chrome 和 Safari)中运行良好,但在 Firefox 或 IE 中根本无法运行,我希望有人能指出我的错误?

我正在做的是使用 jQuery 提取 GeoRSS 提要,然后使用 Leaflet 在地图上绘制位置点。不知何故,使用 Firefox 或 IE 时没有绘制点? 这是有问题的页面:http://bit.ly/19N0I75

这是代码:

var map = L.mapbox.map('map', 'primitive.geography-class').setView([42, 22], 4);

var wordpressIcon = L.icon({
iconUrl: 'http://www.shifting-sands.com/wp-content/themes/shiftingsands/images/icons/wordpress.png',

iconSize:     [18, 18], // size of the icon
shadowSize:   [0, 0], // size of the shadow
iconAnchor:   [9, 9], // point of the icon which will correspond to marker's location
shadowAnchor: [0, 0],  // the same for the shadow
popupAnchor:  [0, 0] // point from which the popup should open relative to the iconAnchor
});

jQuery(document).ready(function($){
$.get("http://shifting-sands.com/feed/", function (data) {
var $xml = $(data);
var $i = 0;
$xml.find("item").each(function () {
    var $this = $(this),
        item = {
            title: $this.find("title").text(),
            linkurl: $this.find("link").text(),
            description: $this.find("description").text(),
            pubDate: $this.find("pubDate").text(),
            latitude: $this.find("lat").text(),
            longitude: $this.find("long").text()
        }

                lat = item.latitude;
                long = item.longitude;
                title = item.title;
                clickurl = item.linkurl;

                //Get the url for the image.
                var htmlString = '<h4><a href="' + clickurl + '" target="_blank">' + title + '</a></h4>';                       
                var contentString = '<div id="content">' + htmlString + '</div>';   

                //Create a new marker position using the Leaflet API.
                var rssmarker = L.marker([lat, long], {icon: wordpressIcon}).addTo(map);

                //Create a new info window using the Google Maps API

                rssmarker.bindPopup(contentString, {closeButton: true});


    $i++;
});
});
});

谢谢!

【问题讨论】:

  • 适用于 Firefox 24 - mac
  • “无效的 LatLng 对象”?
  • “错误:无效的 LatLng 对象:(, )”在 mapbox.js 中。作为一种猜测,我会说对象文字中的最后一个属性后面有一个逗号。
  • @AnthonyGrist 我在想类似的事情,但为什么会说 Invalid LatLng object 而不是报告更通用的语法错误? Javascript 对 LatLng 对象一无所知。我怀疑这个错误是由 mapbox.js 报告的,抱怨一些输入数据。

标签: javascript jquery google-chrome firefox cross-browser


【解决方案1】:

因为 lat 值是命名空间 (geo:lat),所以您无法从 find() 中获得任何价值。因此出现错误(,),两个空值,用逗号分隔。您必须将查询更改为:

latitude: $this.find("geo\\:lat").text()

双反斜杠转义冒号。

【讨论】:

  • 感谢您的帮助。然而,令人困惑的是,这在 Chrome、Safari 和 Opera 中破坏了它。这是您所做更改的地图:bit.ly/19XLQEL
  • 解决了! jQuery 中的一个 bug 意味着它需要是 latitude: $this.find("geo\\:lat, lat").text() longitude: $this.find("geo\\:long, long").text()
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-11
  • 1970-01-01
  • 2019-12-06
  • 2017-06-07
  • 1970-01-01
相关资源
最近更新 更多