迭代+替换脚本
$(".IT_Badge").each(function(){
var badges = $(".IT_Badge").val().trim().split(",");
for (c = 0; badges.length > c; c++) {
currentBadge = badges[c];
currentBadge.replaceWith($("<img/>").attr("src", 'IT_Badges/' + badges[c] + '.png'));
}
});
我有多个包含关键字的跨度。我需要用 src 为关键字的图像替换关键字。但是,我担心放置在跨度中的图像将放置在名为 IT_Badge 的所有跨度中,因此需要 for 循环和each。我希望替换是在一个跨度的基础上进行的。
$(".IT_Badge").each(function(){
var badges = $(".IT_Badge").val().trim().split(",");
for (c = 0; badges.length > c; c++) {
currentBadge = badges[c];
currentBadge.replaceWith($("<img/>").attr("src", 'IT_Badges/' + badges[c] + '.png'));
}
});
I have multiple spans with keywords in them. I need to replace the keywords with images who's src is the keyword. However, i'm worried that the images placed in the span will be placed in all spans called IT_Badge, hence the for loop and the each. I want the replacement to be on a span by span basis.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会在第一次迭代中每次都将 iconInst 设置为数组。看起来 iconInst 在第二次迭代时不是一个数组。这是拼写错误吗?我认为您打算这样做
,如果是这种情况,请更新问题,我们将从那里继续,如果不是,我不太清楚您要处理的问题是什么。
You are not setting iconInst to an array every time in the first itteration. It appears that iconInst is not an array by the second itteration. Is this a typo? I think you intended to do
If that is the case, please update the question and we'll continue from there, if not I am not very clear as to what the issue you are trying to deal with is.