无法通过Jquery 1.4清除用于ajax实现的重写提交方法的文本字段

我有一个function是将消息发布到一个通过Jquery使用AJAX工作的组。 当我点击“发布”按钮这是submit_tag的值时,将呈现javascript并且不重新加载的页面会显示发布的最新消息。 基本上调用post_message.js.erb文件。 我正在利用以下教程来实现相同的目标: – http://railscasts.com/episodes/136-jquery

post_message.js.erb的代码如下所示: –

$("#new_post").before('
'); $("#latest_post").prepend(" by
ago



"); $("#post_msg")[0].reset();

表单的一部分,否则将呈现HTML并显示已重新加载页面的已发布消息,如下所示:

  {:action => :post_message, :id => params[:id]},:html => {:multipart => 'true', :id => 'new_post'},:id => 'post_form' do |f| -%> Start Discussion: <!-- --> 

<!---->
by
ago



我想清空文本字段以及上面已经实现的function。 我想,我需要一些如何使用Javascript reset方法,但在某些地方我没有正确使用它。

请帮助我。

谢谢你的帮助..

[编辑]

我的组控制器中的post_message代码。

 def post_message @investor_group = InvestorGroup.find(params[:id]) unless @current_user.is_an_existing_member_of_group(@investor_group) flash[:notice] = "Please join this group to participate in discussions" redirect_to :action => :show, :id => @investor_group and return # try to find out what exactly does this command do with return stmnt else @group_post = GroupPost.new(params[:group_post]) end #@group_post = GroupPost.new(params[:group_post]) investor_id = session['investor_id'] @group_post.investor_group_id = @investor_group.id @group_post.post_by = investor_id if @group_post.message.blank? flash[:notice] = 'Post can\'t be blank.' end if @group_post.save flash[:notice] = 'Post was successfully created.' # redirect_to :action => :show, :id => params[:id] - removed after trying to implement ajax via jquery else flash[:notice] = 'Post was not successfully created.' end respond_to do |format| format.html {redirect_to :action => "show", :id => params[:id]} format.js end end 

我假设你想要这样的东西:

 $('#post_msg input').val(''); 

这将清除消息输入框的值。