If I have the following tag. What is the best JQuery methodto extract the value for "page" from the href.
Bạn đang xem: How to get href value property for anchor tag in jquery?
2Malcolm
var pageNum = $("#specificLink").attr("href").match(/page=(<0-9>+)/)<1>;
var link = $("a").attr("href");var equalPosition = link.indexOf("="); //Get the position of "="var number = link.substring(equalPosition + 1); //Split the string & get the number.I dont know if you"re gonna use it for paging and have the text in the -tag as you have it, but if you should you can also do
var number = $("a").text();
$("a#myLink").attr("href");Then take a look at this plugin:http://plugins.jquery.com/project/query-object
It will help you handle all kinds of querystring things you want to lớn do.
/Peter F
Xem thêm: Bí Quyết Trắng Da Của Ngọc Trinh, Học Để Có Làn Da Trắng Hồng
var liên kết = $("a").attr("href");if (link.indexOf("?") != -1) var query = link.split("?")<1>; eval("query = " + query.replace(/&/ig, "",").replace(/=/ig, ":"") + "";"); if (query.page) alert(unescape(query.page)); else alert("No page parameter"); else alert("No querystring");I"d go with a library lượt thích the others suggest though... =)
But avoid …
Asking for help, clarification, or responding lớn other answers.Making statements based on opinion; back them up with references or personal experience.To learn more, see our tips on writing great answers.
By clicking “Post Your Answer”, you agree lớn our terms of service, privacy policy và cookie policy
Your privacy
By clicking “Accept all cookies”, you agree Stack Exchange can store cookies on your device và disclose information in accordance with our Cookie Policy.