>. 가능한 Duplicate: >. [쿼리 문자열 값이 어떻게 해야 할까요?] (https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values)
텍스트 - 끝 - < 자동으로 삽입됨 >;!
나는 다음 URL:
<! - 언어: > 랑 없음 -;
http://www.mysite.co.uk/?location=mylocation1
What I need is 의 값을 얻을 수 있는 '위치' 에서 변수 및 URL 에 사용할 경우 it jQuery 코드:
var thequerystring = "getthequerystringhere"
$('html,body').animate({scrollTop: $("div#" + thequerystring).offset().top}, 500);
어떻게 아는 사람 또는 그 값을 잡기 위해 JavaScript 를 사용하여 jQuery?
출처: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html
이게 합니다:)
다음 코드는 url 이 포함된 JavaScript 객체로 반환되므로 매개변수입니다:
// Read a page's GET URL variables and return them as an associative array.
function getUrlVars()
{
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
예를 들어 있는 경우, URL:
http://www.example.com/?me=myValue&name2=SomeOtherValue
이 코드는 반환되므로:
{
"me" : "myValue",
"name2" : "SomeOtherValue"
}
할 수 있습니다.
var me = getUrlVars()["me"];
var name2 = getUrlVars()["name2"];
현행 전체 크리스트링 읽어들이려면 url 을 시작으로 '?' 문자를 사용할 수 있습니다.
location.search
https://developer.mozilla.org/en-US/docs/DOM/window.location
예: "'js 랭 A = b = b123 a% 20a&, // uirl = https://example.com? 콘솔드로그 (로카션.시치); A = b = b123" 20a& a% " // 인쇄,,? "'
이와 관련해 특정 크리스트링 매개변수입니다 있지만, 동시에 같은 검색 클래스뿐만 '우를시치파람스' 및 'uirl' # 39, Internet Explorer 에서 지원하는 aren& 타임코드가, 그들은 이 시점에서, 그리고 아마 피할 수 없다. 이 같은 일이 대신 시도해 볼 수 있습니다. "'js 랭 /*
반품하십시오 {}; }
/*
그래서 위의 같은 사용할 수 있습니다. "'js 랭 로카션.시치 사용하여 // 이제 우를파람스 = 제우를파람스 (로카션.시치); A = b =, = " // solaris. 로카션.시치 2b2" 1&;? 콘솔드로그 (우를파람스); {&Quot a" //, 인쇄,: 1, " b";: " 2b2"; }
Url 을 사용하여 문자열이어야 // a = b =, = & # 39 const uirl A% 20a& 1& # 39 https://example.com?;;; 우를파람스 = 제우를파람스 (url). 콘솔드로그 (우를파람스); {&Quot a" //, 인쇄,: " A" " b":;;; A 1}
// 여부를 확인할 수 있는 매개변수입니다 못하며창조된 됩니다. if (우를파람s.하스운프로페티 (& # 39, parameterName& # 39;) { 콘솔드로그 (우를파람s.파라머턴임); }
"'
이를 위해 일부 jQuery 쉽게 볼 수 있습니다, Firefox, Chrome 그냥 바로 볼 수 있는 JS 콘솔입니다 출력입니다.
var queries = {};
$.each(document.location.search.substr(1).split('&'),function(c,q){
var i = q.split('=');
queries[i[0].toString()] = i[1].toString();
});
console.log(queries);
투명지에 이걸봐 [스택 오버플로 오토메이티드] [1].
function getParameterByName(name, url) {
if (!url) url = window.location.href;
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
return decodeURIComponent(results[2].replace(/\+/g, " "));
}
애니메이션할 방법을 사용할 수 있습니다.
예:
var thequerystring = getParameterByName("location");
$('html,body').animate({scrollTop: $("div#" + thequerystring).offset().top}, 500);
[1]: # 901144 https://stackoverflow.com/questions/901115/get-querystring-values-with-jquery/901144
We do this way.
String.prototype.getValueByKey = function (k) {
var p = new RegExp('\\b' + k + '\\b', 'gi');
return this.search(p) != -1 ? decodeURIComponent(this.substr(this.search(p) + k.length + 1).substr(0, this.substr(this.search(p) + k.length + 1).search(/(&|;|$)/))) : "";
};