Encapsulate the parameter method intercepted into the url address

Encapsulate the parameter method intercepted into the url address


//https://www.baidu.com?add=123

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]));//会中文乱码
	if (r != null) return decodeURI((r[2]));//解决了中文乱码
	return null;
};

//使用:
let add = this.getQueryString("url地址中的参数名")
console.log(add) //123 

Guess you like

Origin blog.csdn.net/chb19991118/article/details/120528023