Last active
August 6, 2021 01:49
-
-
Save EricYue2012/6a4973936dc17554433b94ece9b1b5f2 to your computer and use it in GitHub Desktop.
javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1. 按名字取得网址中的query string | |
function getParameterByName(name) { | |
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); | |
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), | |
results = regex.exec(location.search); | |
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
// example | |
// current URL: http: //www.test.com/index.php?name=John | |
getParameterByName('name') retrun 'John'. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment