[英]How to get page number or specific param from href link
I am trying to do my pagination using ajax and trying to fetch the page number only from the href pagination link. 我正在尝试使用ajax进行分页,并尝试仅从href分页链接中获取页码。 I have other params in href as well.
我在href中还有其他参数。
<a href="?page=2&order_by=asc">2</a>
I need only 2 so that i can send it to ajax request. 我只需要2,以便我可以将其发送到ajax请求。
you may try below 您可以在下面尝试
function getURLParameter(url, name) {
return (RegExp(name + '=' + '(.+?)(&|$)').exec(url)||[,null])[1];
}
$('a').on('click',function(){
var url = $(this).attr('href');
var page_no = getURLParameter(url, 'page');
console.log(page_no);
});
Hope , it will help you 希望对您有帮助
You can use replace
to get the page number: 您可以使用
replace
获取页码:
$('a').on('click', function() { var number = $(this).attr('href') number = number.replace(/\\D/g, ''); console.log(number); return false; })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <a href="?page=2&order_by=asc">2</a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.