我希望使用JQuery从href属性字符串中提取值。
我需要将这些值解析为数组。
$(this).attr("href")
将会给我
?sortdir=ASC&sort=Vendor_Name
我需要将这些值解析为数组。
myArray['sort']
myArray['sortdir']
有什么想法吗? 谢谢!
顺便说一下,在 Stack Overflow 的其他地方,我看到了以下类似的想法可以与查询字符串一起使用。 目前我还无法为我的需求进行调整。
var urlParams = {};
(function () {
var match,
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
query = window.location.search.substring(1);
while (match = search.exec(query))
urlParams[decode(match[1])] = decode(match[2]);
})();