使用jQuery Rails observe_field

有没有jRails使用jQuery的Rails / Prototype observe_field方法?

我正在使用will_paginate进行搜索:


  2, 
                   :update =>'results',
                   :loading =>“Element.show('spinner')”,
                   :complete =>“Element.hide('spinner')”, 
                   :url => {:controller =>'foo',:action =>'search'}, 
                   :with =>“'search ='+ escape(value)”)%>

使用jQuery,你需要使用一个选择器,这样的东西应该工作

$("#search").bind("blur", function() { $("#spinner").show(); // show the spinner var form = $(this).parents("form"); // grab the form wrapping the search bar. var url = form.attr("action"); // grab the URL from the form's action value. var formData = form.serialize(); // grab the data in the form $.get(url, formData, function(html) { // perform an AJAX get, the trailing function is what happens on successful get. $("#spinner").hide(); // hide the spinner $("#results").html(html); // replace the "results" div with the result of action taken }); }); 

回应评论

如果你想对keyup做出反应,那么用第一行替换

 $("#search").bind("keyup", // etc...