我试图在将 URL 粘贴到 #video_url
时提交表单 #url_form
。 .loading
类已正确添加,但表单仍未提交。
代码如下:
$(document).ready(function(){
$("#url_form").live("paste", "#video_url", function(){
$("#video_url").addClass("loading");
$("#url_form").submit();
});
});
和 HTML:
<form accept-charset="UTF-8" action="/posts/get_video" data-remote="true" id="url_form" method="post">
<input autofocus="autofocus" class="post-modal-url loading" id="video_url" name="video_url" placeholder="Paste a URL here" required="required" type="url">
</form>
Rails 表单标签:
<%= form_tag get_video_posts_path, :remote => true, :id => "url_form" do -%>
<%= url_field_tag 'video_url', params[:video_url], :placeholder => "Paste a URL here", :required => true, :autofocus => true, :class => "post-modal-url" -%>
<% end -%>
最佳答案
改变
$("url_form").submit();
至
$("#url_form").submit();
关于javascript - 从 live() 触发时,jQuery Submit() 不会触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13281260/