我有一个function是将消息发布到一个通过Jquery使用AJAX工作的组。 当我点击“发布”按钮这是submit_tag的值时,将呈现javascript并且不重新加载的页面会显示发布的最新消息。 基本上调用post_message.js.erb文件。 我正在利用以下教程来实现相同的目标: – https://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('');
这将清除消息输入框的值。
以上就是jQuery教程分享无法通过Jquery 1.4清除用于ajax实现的重写提交方法的文本字段相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/jquerytutorial/547804.html