Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: 如何在 JavaScript 中获取“GET”请求参数? jQuery querystring 如何在 JavaScript 中获取查询字符串值?
Javascript 没有提供一个核心方法来做到这一点,那么怎么做呢?
function getURLParameter(name) { return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [null, ''])[1].replace(/\+/g, '%20')) || null; }
所以你可以使用:
myvar = getURLParameter('myvar');