我如何用javascript替换一个类下多个位置的单词?
我正在编写一个chrome扩展来为一个项目重新设计tumblr仪表板 这是一件小事,但一直很令人沮丧。我想在每篇文章下面的注释数量之后去掉“注释”这个词 字符串在一个类下。注意\u link\u current,所以我尝试了这个我如何用javascript替换一个类下多个位置的单词?,javascript,replace,google-chrome-extension,Javascript,Replace,Google Chrome Extension,我正在编写一个chrome扩展来为一个项目重新设计tumblr仪表板 这是一件小事,但一直很令人沮丧。我想在每篇文章下面的注释数量之后去掉“注释”这个词 字符串在一个类下。注意\u link\u current,所以我尝试了这个 var textNotes = $('.note_link_current').text(); textNotes = textNotes.replace('notes', ' '); $('.note_link_current').text(textNotes);
var textNotes = $('.note_link_current').text();
textNotes = textNotes.replace('notes', ' ');
$('.note_link_current').text(textNotes);
似乎发生的是,我得到了所有帖子的所有注释的组合字符串。。我如何获得它,使其单独影响所有人
现在我得到的是这样的东西:
251
63 notes441 notes74 notes851 notes49,263 notes2,561 notes142 notes1 note651 notes
任何帮助都将不胜感激 费利克斯克林说了些什么,但有更多的解释: 类似于
$('.note\u link\u current')
的jQuery选择器将返回一个节点数组。您正在尝试对此阵列执行操作,就像它是一个节点一样
相反,您应该做的是调用.each()
,对每个元素执行操作
$('.note_link_current').each( function(index) {
// Inside this function, "this" refers to the (DOM) element selected
var text = $(this).text();
/* ... */
});
->