Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 循环和抓取href链接信息 1 ... 直到第10页 _Javascript_Jquery_Jsp - Fatal编程技术网

Javascript 循环和抓取href链接信息 1 ... 直到第10页

Javascript 循环和抓取href链接信息 1 ... 直到第10页 ,javascript,jquery,jsp,Javascript,Jquery,Jsp,我想循环href class=“pag curr”以获取计数的数量并获取它们的相对href信息(例如blahblah;page_num=2..etc),如何使用javascript或jquery实现它?使用jquery,您可以使用选择器实现这一点: <p class="page" id="datapage"> <strong>1</strong> <a class="pag-curr" href="blahblah;page_num=2">

我想循环href class=“pag curr”以获取计数的数量并获取它们的相对href信息(例如blahblah;page_num=2..etc),如何使用javascript或jquery实现它?

使用jquery,您可以使用选择器实现这一点:

 <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>
$(".pag-curr").each(function(){
   var hrf = $(this).attr("href");
});
// 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"));
}