我有一个互动式地图,我正在使用rss订阅源。地图本身是在SVG中创建的,每个“检查点”的类别为circle
,并增加为circle+k
(circle1,circle2,circle3等)。我的RSS提要将确定有多少前述圈将得到一类filled
,以填补他们的颜色保存一个变量,特别是在jQuery中增加的div?
我编程做上述,我跑2个各功能来增加每个格,像这样:
//increments circle class on the map's dots
$("#map .circle").each(function(k) {
$(this).addClass("circle" + (k + 1));
});
//increments step class on the rss-fed items
$(".gs-rss-feed .hs-rss-item").each(function(i) {
$(this).addClass("step" + (i + 1));
//if circle class + number = step class + number, add class filled to circle
$("#map .circle").eq(i).addClass("filled");
});
但现在我需要做2多余的东西,访问来自各个RSS职位(title
和url
)的某些信息。这些都是在课堂上都做了,所以我应该能够得到像这样的信息:
//Get link from html
var link = $('.hs-rss-title').attr('href').split('=');
//Get title
var title = $('.hs-rss-title span').html();
那么我就需要使用.wrap();
我的问题来包装每一个圆圈在我的地图我遇到麻烦的是,如何将每个变量(title
和url
)都限定在每个特定的点上。如果我使用上述保存变量的方法,那么尝试使用$("#map .circle").eq(i).wrap("<a href="+link+"></a>");
它最后只会添加第一个示例,即:将第一个RSS项目的url添加到地图上的每个点。
他们是一个更好的方法,我可以将其范围?这里是我的codepen,任何帮助表示赞赏!
您可以在元素上使用自定义数据属性,然后再拉取它。像data-title =“Something”data-href =“http://www.google.com” –
由于它在技术上将成为rss提要,所以我无法编辑html结构。 –