我见过很多jQuery示例,其中参数大小和名称未知
我的URL只有一个字符串:
http://example.com?sent=yes
我只想检测:
- 发送的
是否存在 - 它等于“是”吗
这里是最好的解决方案
var getUrlParameter=函数getUrlParameter(sParam){
var sPageURL=window.location.search.substring(1),
sURLVariables=sPageURL.split(“&;”),
sParameterName,
我
对于(i=0;i<;sURLVariables.length;i++){
sParameterName=sURLVariables[i].split('=');
if(sParameterName[0]==sParam){
返回类型sParameterName[1]==未定义?true:decodeURIComponent(sParameterName[1]);
}
}
返回false;
};
假设URL为,
则可以使用此函数
http://dummy.com/?technology=jquery&blog=jquerybyexample
var-tech=getUrlParameter('technology');
var blog=getUrlParameter('blog');