请那些知道如何创建类似自动建议搜索框的 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>
代码似乎不起作用,它甚至没有响应
请问有人知道如何以更有效的方式实现此功能
我真的需要帮助