jQuery submit()在从live()触发时不触发

时间:2012-11-08 01:45:26

标签: javascript jquery

我正在尝试将网址粘贴到#url_form时提交#video_url表单。正确添加了.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:

 <%= 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 -%>

1 个答案:

答案 0 :(得分:3)

变化

 $("url_form").submit();

$("#url_form").submit();