javascript - jQuery 在 Chrome 和 Safari 中工作,但不能在 Firefox 或 IE 中工作?

标签 javascript jquery google-chrome firefox cross-browser

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

我正在做的是使用 jQuery 引入 GeoRSS 提要,然后使用 Leaflet 在 map 上绘制位置点。使用 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++;
});
});
});

谢谢!

最佳答案

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

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

双反斜杠转义冒号。

关于javascript - jQuery 在 Chrome 和 Safari 中工作,但不能在 Firefox 或 IE 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19447881/

相关文章:

javascript - Chrome 扩展、内容脚本和 XSS 攻击

javascript - jQuery 从选择框中显示两个按钮

javascript - Angular Routing 1.6 帮助

jquery - 使用 jQuery 进行电子邮件验证

google-chrome - chrome 弹出窗口和面板之间的区别

javascript - 收听 Google Chrome 中所有页面的 KeyStrokes

javascript - 如何动态构建Mongodb聚合语句?

javascript - 使用 jQuery 从多个表中删除行

javascript - 克隆 JavaScript 对象。又是:(

jquery - 单击大纲?