gpt4 book ai didi

javascript - 保存变量,特别是保存到 jQuery 中递增的 div 中?

转载 作者:行者123 更新时间:2023-12-03 03:58:42 26 4
gpt4 key购买 nike

我正在构建一个使用 rss feed 的交互式 map 。 map 本身是在 SVG 中创建的,每个“检查点”都有 circle 类。并增加为circle+k (圆 1、圆 2、圆 3 等)。我的 RSS Feed 将确定有多少上述圈子将获得 filled 类。 ,填充它们的颜色。

我以编程方式执行上述操作,其中运行 2 个每个函数来递增每个 div,如下所示:

//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 帖子中访问某些信息( titleurl )。这些都是在类里面完成的,所以我应该能够像这样获取他们的信息:

//Get link from html
var link = $('.hs-rss-title').attr('href').split('=');
//Get title
var title = $('.hs-rss-title span').html();

然后我需要使用 .wrap(); 包裹 map 上的每个圆圈。

<小时/>

我遇到麻烦的问题是,如何将每个变量( titleurl )的范围限定到每个特定点。如果我使用上述方式保存变量,则尝试使用 $("#map .circle").eq(i).wrap("<a href="+link+"></a>");它最终只附加第一个示例,即:将第一个 RSS 项目的 url 添加到 map 上的每个点。

他们是我确定范围的更好方法吗?这是我的codepen ,感谢任何帮助!

最佳答案

我还没有足够的声誉来发表评论,所以我必须将此作为答案发布..

你不能在那一秒内做这个吗?

//increments step class on the rss-feed items
$(".gs-rss-feed .hs-rss-item").each(function(i) {
var $rss-item = $(this);
$rss-item.addClass("step" + (i + 1));
//if circle class + number = step class + number, add class filled to circle
var $circle = $("#map .circle").eq(i);
$circle.addClass("filled");

//Get link from html
var link = $rss-item.find('.hs-rss-title').attr('href').split('=');
//Get title
var title = $rss-item.find('.hs-rss-title span').html();

// here you can wrap $circle and do whatever you want with this link and title
});

与您的问题并不真正相关,但您为什么要在 = 上拆分 href?除了缺少一些斜杠之外,我在给定的 href 属性中没有看到任何需要在 = 上拆分的内容。

关于javascript - 保存变量,特别是保存到 jQuery 中递增的 div 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44826347/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com