TwitterやFacebookのような自動提案検索ボックスの作成方法を知っている人はいますか? 私はしばらくの間これを実装しようとしてきました...ここにリンクの説明を入力して得たコードがあります。
<div class="search_index">
<div id = "testsearch">
<%=render :partial => 'search'%> // partial where the updated search elements will appear from
</div>
<%=form_tag(search_path,:method=>'get',:remote=>true) do%>
<%=text_field_tag :search%>
<%= submit_tag "search" ,:name=>nil%>
<%end%>
<%= set_focus_to_id 'search' %> // I have a helper "set_focus_to_id"
<script> // small javascript file :)
document.observe("dom:loaded", function() { // ensures the page is loaded first
new Form.Element.Observer( // Observes the text_field_tag every 2 seconds
'search',
2,
respondToChange //refrences the function in the Layout
) // on a change in search calls respondToChange
});
</script>
</div>
私が持っているタグで
<script>
function respondToChange() {
$('search').up('form').submit() // The ".up finds the form in the DOM"
};
</script>
コードが機能していないようで、応答さえしません
この機能をより効率的な方法で実装する方法を知っている人はいますか
私は本当にこれについて助けが必要です