我想在提交消息后清除 text_form。这是我的表格:
<%= form_for :chat, :html => {:id => 'send_form'}, :url => {:controller => :chat,
:action => :chat_save }, :remote => true do |f| %>
<%= f.text_field(:text, :class => "text_field round") %>
<%= f.submit(:class => 'button round') %>
<% end %>
我已经完成了,就像在这个主题中一样:提交后清除 Rails 远程表单。首先我在我的 js 文件中尝试这个:
$('#send_form').submit(function() {
$('#chat_text').val('');
});
text_field 变得清晰,但它发送一个空行。然后我试试这个,它现在发送消息,但 text_field 没有变空:
$(document).ready(function () {
$("#send_form").live("ajax:complete", function(evt, data, status, xhr){
$('#chat_text').val('');
});
}
可能会错过一些图书馆吗?任何人都可以帮忙吗?