2012-12-05 204 views
0
<span class='url_link'>1</span> 
<span class='url_link'>2</span> 
<span class='url_link'>3</span> 
<span class='url_link'>4</span> 
<span class='url_link'>5</span> 

$(".url_link").each(function(idx, obj){ 
     console.log(this); // <span class="url_link"> 
    console.log(this.text()); // TypeError: this.text is not a function 
}); 

如何在span标记中对文本进行grep处理?jquery,如何使用foreach获取span标记中的文本

回答

2

使用console.log($(this).text());

你试图使用一个jQuery功能的非jQuery对象上。

jsFiddle example

0
console.log(this.text()) 

应该

console.log($(this).text()) 

.text()jQuery methodDOM Object ..

因此需要将其转换成一个jQuery对象之前你使用.text()就可以了..

如果你想使用本地JavaScript,那么你可以试试这个

console.log(this.innerHTML) 

Check Fiddle

相关问题