JavaScript:QueryString(zz加解释)
function QueryString(fieldName)
{
//假设document.location.herf=http://localhost/myweb/default.aspx?info=1&name=2,fiedName=info
var urlString = document.location.search;//urlString为?info=1&name=2
if(urlString != null)
{
var typeQu = fieldName+"=";
var urlEnd = urlString.indexOf(typeQu);//寻找info=1位置,为1
if(urlEnd != -1)
{
var paramsUrl = urlString.substring(urlEnd+typeQu.length);//paramsUrl=1&name=2
var isEnd = paramsUrl.indexOf('&');
if(isEnd != -1)
{
return paramsUrl.substring(0, isEnd);//得到info值为1
}
else
{
return paramsUrl;//只有一个参数情况
}
}
else
return null;//没有找到info=1
}
else
return null;没有带参数的Url
}
{
//假设document.location.herf=http://localhost/myweb/default.aspx?info=1&name=2,fiedName=info
var urlString = document.location.search;//urlString为?info=1&name=2
if(urlString != null)
{
var typeQu = fieldName+"=";
var urlEnd = urlString.indexOf(typeQu);//寻找info=1位置,为1
if(urlEnd != -1)
{
var paramsUrl = urlString.substring(urlEnd+typeQu.length);//paramsUrl=1&name=2
var isEnd = paramsUrl.indexOf('&');
if(isEnd != -1)
{
return paramsUrl.substring(0, isEnd);//得到info值为1
}
else
{
return paramsUrl;//只有一个参数情况
}
}
else
return null;//没有找到info=1
}
else
return null;没有带参数的Url
}