简单的jQuery代码段,可使用jQuery选择器基于通配符搜索获取所有这些href。 我只是在编写一个jQuery选择器,以根据通配符匹配提取超链接,并认为我会在博客上共享它。
//output all links on page that start with "http://www.jquery4u.com"
$('#j4u-post a[href^="http://www.jquery4u.com"]').each(function (i,v)
{
console.log($(this).attr('href'));
});
现在,将通配符添加到选择器中,我们可以执行以下操作:
$('#j4u-post a[href*="jquery4u.com"]').each(function (i,v)
{
console.log($(this).attr('href'));
});
使用* =本质上表示“喜欢”,而^ =表示开头。 而已。
From: https://www.sitepoint.com/jquery-extract-hyperlinks-specific-href/