我见过很多参数大小和名称未知的jQuery示例.
我的URL将只有一个字符串:
http://example.com?sent=yes
我只想检测一下:
- 有
sent
个吗? - 等于"是"吗?
我见过很多参数大小和名称未知的jQuery示例.
我的URL将只有一个字符串:
http://example.com?sent=yes
我只想检测一下:
sent
个吗?最佳解决方案here.
var getUrlParameter = function getUrlParameter(sParam) {
var sPageURL = window.location.search.substring(1),
sURLVariables = sPageURL.split('&'),
sParameterName,
i;
for (i = 0; i < sURLVariables.length; i++) {
sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] === sParam) {
return sParameterName[1] === undefined ? true : decodeURIComponent(sParameterName[1]);
}
}
return false;
};
And this is how you can use this function assuming the URL is,
http://dummy.com/?technology=jquery&blog=jquerybyexample
.
var tech = getUrlParameter('technology');
var blog = getUrlParameter('blog');