我试图理解查询字符串的工作原理。我了解可以通过使用问号和"&"来传递值。用于将值与基URI分开的标志。例如:www.example.html?value1& value2
我已成功使用下面显示的以下功能,但我很难理解实际发生的情况,而且我无法找到有关它的更多信息。如果有人可以就此代码中发生的事情给我一个解释,我将非常感谢!
function getParameterByName(value) {
value = value.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + value + "=([^&#]*)"),
results = regex.exec(location.search);
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
答案 0 :(得分:1)
您的示例使用正则表达式来解析字符串。您可以在此处了解有关它们的更多信息:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions