如何列出功能中的项目?

抢劫

给定这样的的列表<a>

<tr>
    <th style="padding-right:1em">Location</th>
    <td>
        <span class="location">Lower reaches of the <a href="/wiki/Geum_River" title="Geum River">Geum River</a>, <a href="/wiki/Korea" title="Korea">Korea</a></span>
    </td>
</tr>

JS

function countryList(string) {
  let pattern = new RegExp('^.+\/wiki\/'); // adjust `RegExp`
  countryListLinks = string.replace(pattern, '');
}

我尝试了这个,但是什么也没得到:

  countryLinks.each(function(){
    console.log(countryList);
  });

我尝试了这个,但我只得到一个项目而另一个 undefined

countryLinks.forEach(countryList);

我试图输出每个href但不/wiki/单独输出,以便可以使用它们:

Geum_River Korea
让·弗雷格

试试这个:

let word = '/wiki/';
$('[href]').map(function(i, e) {
  var href = $(e).attr('href');
  console.log(href.substring(href.indexOf(word) + word.length, href.length));
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<tr>
  <th style="padding-right:1em">Location</th>
  <td>
    <span class="location">Lower reaches of the <a href="/wiki/Geum_River" title="Geum River">Geum River</a>, <a href="https://fiddle.jshell.net/wiki/Korea" title="Korea">Korea</a></span>
  </td>
</tr>

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章