HI 我尝试在form_remote_for的submit标签中使用javascript函数调用,但它无法找到函数im调用。 如果我从form_remote_for调用相同的函数,那么ajax停止工作。 当我使用form_remote_for NOT FORM_REMOTE_TAG时,我可以帮助我如何调用javascript函数.... ????
答案 0 :(得分:1)
我认为您需要REMOTE_FORM_FOR。
示例:
在您看来:
<%- remote_form_for(comment, :url => topic_post_comments_path(@topic, post),
:after => "submitComment(self);$('input').disable()") do |f| %>
<%= f.text_field :body, :size => 70, :class => "comment_body" %><br />
<%= f.submit "Submit", :class => "comment_submit" %>
<%- end -%>
注意:javascript函数在:之后是我自定义的javascript函数。
在您的控制器中(这里是comments_controller)
@comment = @post.comments.new params[:comment] # actually, it depends on your model :p
respond_to do |format|
# remember to handle exception here. like if @comment.save or not
format.html
format.js {
render :update do |page|
pagepage.visual_effect :highlight, "comments"
end
}
end
无论如何,这只是一个简单的示例,在您对remote_form_for有所了解之后,您必须处理更多细节。
祝你好运。