我正在使用 rails 表单将图像提交给载波上传器。
<p class="sidebar-title">UPLOAD IMAGE</p>
<%= form_for :page_image, :url => {:controller => :menus, :action => :create_image}, :html => {:multipart => true, :id => "image-upload-form"} do |f| %>
<ul>
<li class="sub-heading">Choose Image</li>
<li><%= f.file_field :image %></li>
<li class="sub-heading" style="text-align: center; width:50%; margin: 1.5em 25%">OR<br></li>
<li class="sub-heading">Image URL</li>
<li><%= f.text_field :remote_image_url %></li></ul>
<ul>
<li class="description"><%= f.radio_button :authored, "true" %>
<%= f.label :authored, "I am the author of this image and give permission for Gastromica to use it.", :value => "true" %></li>
<li class="description"><%= f.radio_button :authored, "false" %>
<%= f.label :authored, "This image is licenced to be freely be used and shared cormercially. If attribution is required please type a url in the box below.", :value => "false" %></li>
<li class="sub-heading">Attribution / Source URL</li>
<li><%= f.text_field :attribution %></li></ul><ul>
<%= f.hidden_field :user_id, :value => "1" %>
<% @attributes.each do |attr| %>
<%= hidden_field_tag attr[0], attr[1]%>
<% end %>
<li><%= f.submit "Submit Image", :class => "image-upload" %></li>
<% end %>
因为用户正在上传我想显示的图像。只是说上传正在进行中。所以为此编写了以下javascript:
('.image-upload').click(function() {
$(this).parents('.content').html('<p class="description" >Please wait, currrently uploading image...</p>')
});
这在 Safari 中运行良好,但在任何其他浏览器中,它会阻止表单提交并且图像永远不会上传。如果没有所有浏览器中的脚本,一切似乎也运行良好。有没有办法可以捕获提交表单 url 并在显示图像加载消息后强制它提交?