我需要的是當用戶在搜索框中鍵入他的查詢時。使用GET請求提交表單到頁面本身
<form class="navbar-search pull-left">
<input type="text" autocomplete="off" autofocus id="query" class="search-query search_input" placeholder="Type your query...">
</form>
我沒有按鈕來提交表單。我希望在用戶按下Enter鍵時提交表單。 而當用戶按Enter鍵時,我希望查詢顯示在URL中。 像提交
http://example.come/
與之前的URL當用戶輸入他的文字,並按下回車鍵。我想查詢顯示在這樣的URL中
http://example.come/#query
沒有重新加載整個。 這是possile使用Javascript或jquery或任何更容易。
編輯: 這是我試過的 window.location.hash = get_query;
if (get_query.length != 0) {
$("#query").val(get_query);
$('.search_input').trigger('keyup'); // This is the Event which triggers
}
是的,這是可能的。閱讀文檔並嘗試一些內容。 – 2012-04-01 11:32:56
老兄我試了一些技巧!但我真的很喜歡它! – 2012-04-01 11:33:49
如果沒有提交按鈕,某些瀏覽器將不會提交表單。然而,看看這個其他Stackoverflow線程:http://stackoverflow.com/questions/699065/submitting-a-form-on-enter-with-jquery – 2012-04-01 11:36:04