js通過location.search來獲取頁面傳來的參數


這篇文章主要介紹了通過window.location.search來獲取頁面傳來的參數,經測試是OK的

?
1
2
3
4
5
function GetQueryString(name) {
var reg = new RegExp( "(^|&)" + name + "=([^&]*)(&|$)" , "i" );
var r = window.location.search.substr(1).match(reg);
if (r!= null ) return (r[2]); return null ;
}
?
1
2
3
4
5
6
var sname = GetQueryString( "name" );
if (sname!= null )
{
var sname_ = decodeURIComponent(sname);
alert(sname_);
}

測試

abcd.html?name=xyz

應該彈出xyz


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM