我有一个链接类似的页面:

<a class="mod-articles-category-title " href="curso-bsc/82-balanced-scorecard/o-bsc-uma-ferramenta-para-melhorar-a-performance-da-organizacao/377-responsabilizacao-e-trabalho-de-equipa">

<a class="mod-articles-category-title " href="curso-bsc/82-balanced-scorecard/o-bsc-uma-ferramenta-para-melhorar-a-performance-da-organizacao/378-recompensas-e-incentivos-baseados-no-bsc">

<a class="mod-articles-category-title " href="curso-bsc/82-balanced-scorecard/o-bsc-uma-ferramenta-para-melhorar-a-performance-da-organizacao/99-vantagens-do-bsc-gestao-da-mudanca">


我需要一个带有最后一个斜杠(/)和以下减号(-)后的数字的数组:

“ 377”,“ 378”,“ 99”

我在用着:

links=$('.mod-articles-category-title').attr('href');


但是我缺少将这些数字放入数组的表达式。有人可以帮忙吗?

最佳答案

var links = [];
$('a.mod-articles-category-title').each(function () {
    links.push($(this).attr('href').match(/(\d+)/g)[1]);
});
console.log(links);


jsFiddle example

07-25 21:57