循环并抓取href链接信息

时间:2012-07-12 09:51:35

标签: javascript jquery jsp

 <p class="page" id="datapage">
 <strong>1</strong> 
 <a class="pag-curr" href="blahblah;page_num=2">
 2
 </a> 
 <a class="pag-curr" href="blahblah;page_num=3">
 3
 </a> 
 ...
 till page number 10
 <a class="pag-next" href="blahblah;page_num=2">
 <strong>next&nbsp;»</strong>
 </a>
 </p>

我想循环href class =“pag-curr”来获取计数的数量,并希望获得他们的相对href信息(例如.blahblah; page_num = 2 ..等),我怎样才能用javascript实现它还是jquery?

2 个答案:

答案 0 :(得分:1)

$(".pag-curr").each(function(){
   var hrf = $(this).attr("href");
});

答案 1 :(得分:1)

使用jQuery,您可以使用选择器执行此操作:

// Retrieve all links with class pag-curr
var links = $("a.pag-curr");

// Count links
console.log(links.length);

// Print all href attributes
links.each(function() {
  console.log($(this).attr("href"));
}