Last active
August 29, 2015 14:03
-
-
Save noel9999/0297dfb2bbb4cb7c8072 to your computer and use it in GitHub Desktop.
Javascript:抓query_string,可能還是有缺陷,但自己寫的就先這樣吧,有問題的話儘管提出討論吧~
This file contains 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
//運用正規表示法 | |
function getParameterByName(name) { | |
var results = RegExp("[\\?&]" + name + "=([^&#]*)").exec(location.search); | |
return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); | |
} | |
//運用一般陣列 | |
function getParameterByName2(name){ | |
var object = {}; | |
var pairs = location.search.substring(1).split("&"); | |
for(pair in pairs) | |
{ | |
var key = pairs[pair].split("=")[0]; | |
var value = pairs[pair].split("=")[1]; | |
object[key]=value; | |
} | |
return object[name]=="undefined" ? " " : object[name]; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment