获取url参数
方法一:
function getParamValue( url, key ) {
if ( typeof url !== "string" || typeof key !== "string" ) return "";
var index = url.indexOf( key + "=");
if ( index === -1 ) return "";
url = url.substr( index + 1 + key.length );
index = url.indexOf( "&" );
return index === -1 ? url : url.substr( 0, index );
}
方法二:
function getParamValue( url, key ) {
if ( typeof url !== "string" || typeof key !== "string" ) return "";
var reg = new RegExp( "[?&]" + key + "=([^& ]*)&?" );
var matches = reg.exec( url );
if ( matches ) {
return matches[1];
}
return "";
}