0

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>

コードが機能していないようで、応答さえしません

この機能をより効率的な方法で実装する方法を知っている人はいますか

私は本当にこれについて助けが必要です

4

1 に答える 1

2

適切なオプションは、既存のスクリプトを使用することです。

  1. http://tweet.seaofclouds.com/
  2. http://jquery.malsup.com/twitter/

彼らは独自に作成し、考慮に値するいくつかの機能を備えています。または使用することさえあります。

于 2012-09-27T00:08:55.473 に答える