2011-10-31 2 views
0

나는 일부 jQuery 코드를 사용하고 싶습니다 :jQuery를 사용하여 새 페이지를 열려면 어떻게해야합니까?

a) Watch for when an element #RetrieveData is clicked 
b) Get the value of #DataSource and put this into xxx 
c) Open up a new page with url "/person/ds=xxx 

나는 아약스 호출과 비슷하지만 결코 새로운 페이지를 호출 뭔가 일을했습니다. 누군가 제가 이걸 어떻게 할 수 있는지 조언 해 줄 수 있습니까?

+0

당신은 아약스와 함께이 작업을 수행 한 코드를 재사용 할 수 호출 /en/DOM/window.location) –

답변

3
$('#RetrieveData').click(function() { 
    var xxx = $('#DataSource').val(); 
    window.location.href = '/person?ds=' + encodeURIComponent(xxx); 
    return false; 
}); 
+0

위대한 예제를 가져 주셔서 감사합니다 –

0

"새 페이지"를 쓸 때 새 창 또는 페이지 리디렉션을 의미합니까? 대신 새 페이지를 열 만들기 ([`location`]를 사용하여 https://developer.mozilla.org을 사소한 -

http://jsfiddle.net/DTG7G/5/

$('#RetrieveData').click(function(e) { 
    e.preventDefault(); 
    var xxx = $('#DataSource').val(); 

    //open in new window 
    //window.open('/person?ds=' + encodeURIComponent(xxx)); 

    //open in same window 
    window.location.href = '/person?ds=' + encodeURIComponent(xxx); 
}); 
관련 문제