【发布时间】:2016-01-22 16:46:54
【问题描述】:
就是这种情况:我有多个 <span> 标签,其类为 .productLink,其中一个链接 (<a>) 包含指向页面的链接。
示例
<span class="productLink">
<a href="/Products/Category/item.html">A very nice product</a>
</span>
<span class="productLink">
<a href="/Products/Category/otheritem.html">Also very nice product</a>
</span>
现在我想用 jQuery 检索这些链接。
我试过了:
$('.productLink').each(function(index){
console.log($(this + ' a').attr('href'));
});
但它扔了:
未捕获的语法错误,无法识别的表达式:[object HTMLSpanElement]
我需要改变什么?
【问题讨论】:
标签: jquery html url hyperlink href