JavaScript獲取URL中參數

function getQueryString(name) 
{
				var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
				var r = window.location.search.substr(1).match(reg);
				if (r != null) {
					return unescape(r[2]);
				}
				return null;
}

//獲取URL中code參數
//http://xxx.xxx.com?code=123
var code = getQueryString('code');

//now code = 123

參考:
https://blog.csdn.net/qq_36947128/article/details/78594462
https://www.cnblogs.com/c9999/p/5852597.html
https://www.runoob.com/w3cnote/js-get-url-param.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章