2011-07-04 53 views
5

我期待追加一個變種的URL與一個函數,我有bounf點擊事件。追加一個變種的URL與jQuery的功能

說網址是www.example.com

運行後它變成了函數。

www.example.com?folder=beats

我已經拿到了功能抓住了正確的文件夾值,但需要將其追加到當前頁面的URL。

function fileDialogStart() { 

$folder = $('#ams3Folder').val(); 



} 

任何幫助

+1

瀏覽器的網址或只是一些字符串? –

+1

使用'var'來聲明變量,所以你不會創建一個隱含的全局變量。 –

回答

8
function fileDialogStart() 
{ 
    var newURLString = window.location.href + 
      "?folder=" + $('#ams3Folder').val(); 

    window.location.href = newURLString; // The page will redirect instantly 
              // after this assignment 
} 

欲瞭解更多信息,請here

+1

David Walsh也在'window.location'上有一個很棒的頁面:http://davidwalsh.name/javascript-window-location – StuperUser

3
function fileDialogStart() { 

$folder = $('#ams3Folder').val(); 

window.location.href = window.location.href + $folder 

// window.location.href = window.location.href + '?test=10'; 

} 
+1

嗨tarek只是一個問題,如果我運行它兩次我得到www.example.com?folder=節拍?文件夾=節拍哪些混亂? – DCHP

+0

你有2個選項:在追加變量之前使用replace()清理location.href或者做一些類似的操作:window.location.href ='index.php?'+ $ folder – Tarek

+0

ok生病請試試,謝謝 – DCHP