接收3个参数
querystring.stringify({name:'dyh',course:['jade','node'],from:'zh'})
//运行结果
'name=dyh&course=jade&course=node&from=zh'
querystring.stringify({name:'cg',course:['jade','node'],from:'zh'},'$')
//运行结果
'name=cg$course=jade$course=node$from=zh'
querystring.stringify({name:'dyh',course:['jade','node'],from:'zh'}, '$', ':')
//运行结果
'name:dyh$course:jade$course:node$from:zh'
接收3个参数
querystring.parse('name=dyh&course=jade&course=node&from=zh')
// 运行后
{
name: 'dyh',
course: ['jade', 'node'],
from: 'zh'
}
querystring.parse('name=dyh$course=jade$course=node$from=zh', '$')
// 运行后
{
name: 'dyh',
course: ['jade', 'node'],
from: 'zh'
}
querystring.parse('name:dyh$course:jade$course:node$from:zh', '$', ':')
// 运行后
{
name: 'dyh',
course: ['jade', 'node'],
from: 'zh'
}
querystring.escape('小代')
'%E5%B0%8F%E4%BB%A3'
querystring.unescape('%E5%B0%8F%E4%BB%A3')
'小代'
function getQueryString(name) {
var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
var r = window.location.search.substr(1).match(reg);
if (r != null) {
return unescape(r[2]);
}
return null;
}
// 这样调用:
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
var Request = new Object();
Request = GetRequest();
// var 参数1,参数2,参数3,参数N;
// 参数1 = Request['参数1'];
// 参数2 = Request['参数2'];
// 参数3 = Request['参数3'];
// 参数N = Request['参数N'];
https://jackiehao.blog.csdn.net/?q=dyh,我们想得到参数q的值
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
var context = "";
if (r != null)
context = r[2];
reg = null;
r = null;
return context == null || context == "" || context == "undefined" ? "" : context;
}
alert(GetQueryString("q"));
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
if (url.indexOf("?") != -1) { //判断是否有参数
var str = url.substr(1); //从第一个字符开始 因为第0个是?号 获取所有除问号的所有符串
strs = str.split("="); //用等号进行分隔 (因为知道只有一个参数 所以直接用等号进分隔 如果有多个参数 要用&号分隔 再用等号进行分隔)
alert(strs[1]); //直接弹出第一个参数 (如果有多个参数 还要进行循环的)
}
}