2013-03-27 98 views

回答

0

你可以試試這樣的腳本。

var str=window.location.href; var n=str.split("="); alert(n[1]); 

該代碼將URL分割爲=,然後返回數據。

1

這裏是小功能,它

<script type="text/javascript"> 
function $_GET(q,s) { 
    s = s ? s : window.location.search; 
    var re = new RegExp('&'+q+'(?:=([^&]*))?(?=&|$)','i'); 
    return (s=s.replace(/^?/,'&').match(re)) ? (typeof s[1] == 'undefined' ? '' : decodeURIComponent(s[1])) : undefined; 
} 
</script> 

使用

<script type="text/javascript"> 
    alert('GET var myVar = '+$_GET('myVar')); 
</script> 
+0

謝謝!經過測試,並做我所需要的!但我認爲其他答案更短,並做到了。 – DaZa 2013-03-27 18:32:29