我为在Webkit浏览器(Chrome和Safari)中完美运行而编写的一些JavaScript / jQuery代码感到困惑,但在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++;
});
});
});


谢谢!

最佳答案

由于lat值是命名空间(geo:lat),因此find()中没有任何值。因此,错误(,),两个空值,用逗号分隔。您必须将查询更改为此:

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


双反斜杠可避免冒号。

10-01 06:53