2014-08-30 44 views
0

所以我使用的是形式特定頁面,我想提交如何準確的搜索結果進入一個新的URL

後的確切搜索查詢傳遞到另一個網址:我搜索車,我需要的結果是domain.com/search/vehicles

所以這是我到目前爲止有:

<form id="" action="domain.com/" method="get"> 
<input type="text" name="search" /> 
<input type="submit" value="click here" /> 
</form> 

實際的URL結果這裏是:domain.com/?search=vehicles

我不知道如何使它工作

+0

當您提交表單時,表單將參數傳遞爲參數。你可以使用javascript改變頁面.'document.location.href = newUrl;' – 2014-08-30 18:30:54

回答

0

HTML表單將發送輸入作爲GET或POST(或DELETE或PUT也,我認爲)參數。所以他們會發送它作爲url?parameter1=xxx,他們不會將它們合併到URL中,因爲你想這樣url/parameter1/xxx/。我認爲這樣做是因爲你想要更容易與jQuery(或普通的JavaScript)。

你可以使用jQuery做到這一點,例如:

$("#form-id").submit(function() { 
    event.preventDefault(); // stops form from executing normal behavior 
    var newUrl = // get new url parameters and mount it; 
    document.location.href = newUrl; // sends to new location 
    /* Do Something */ 
    return false; 
}); 

document.location.href在JavaScript將您重定向到一個新的一頁。

相關問題