Javascript 获取URL中得参数值
/*这个要简洁一些*/ 2012、10、9
function GetParam (item) {
var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)", "i"));
return svalue ? svalue[1] : svalue;
}
有时会用到,又懒得花时间去写。备用
<script>
var url = "?aa=1&w=2&cc=3&ss=我要"; //URL参数,你也可以用document.URL来获取,方法太多了
function GetUrlParam(url, paramName )
{
var oRegex = new RegExp( '[\?&]' + paramName + '=([^&]+)', 'i' ) ;
//var oMatch = oRegex.exec( window.top.location.search ) ; //获取当前窗口的URL
var oMatch = oRegex.exec( url ) ;
if ( oMatch && oMatch.length > 1 )
return oMatch[1] ; //返回值
else
return '' ;
}
alert(GetUrlParam(url,"aa"));
alert(GetUrlParam(url,"w"));
alert(GetUrlParam(url,"cc"));
alert(GetUrlParam(url,"ss"));
</script>
引自:http://bbs.blueidea.com/thread-2838141-1-1.html