日期:2014-05-16  浏览次数:20435 次

.js?sid=5
js文件怎么接受参数

------解决方案--------------------
function getParameter(name)
{
var paramStr = location.search;
if( paramStr.length == 0 ) return null;
if( paramStr.charAt( 0 ) != '? ' ) return null;
paramStr = unescape( paramStr );
paramStr = paramStr.substring( 1 );
if( paramStr.length == 0 ) return null;
var params = paramStr.split( '& ' );
for(var i=0;i <params.length;i++)
{
var parts = params[i].split( '= ',2 );
if( parts[0] == name )
{
if(parts.length <2||typeof(parts[1])== "undefined "||parts[1]== "undefined "||parts[1]== "null ")return " ";
return parts[1];
}
}
return null;
}


var p = getParameter( "para ");