【问题标题】:How to display file name before the upload?如何在上传前显示文件名?
【发布时间】:2014-11-02 20:12:40
【问题描述】:

我正在使用blueimp/jQuery-File-Upload,我正在尝试在上传之前显示文件的名称。我正在关注this tutorial,现在一切都按预期工作。唯一的事情是我试图在文件上传之前显示一个文件名。我怎样才能做到这一点?我想在文件开始上传之前显示进度条。

我已经将那个教程中的上传脚本稍微改成了这个,所以上传从用户点击按钮开始:

    jQuery ->
  $('#new_avatar').fileupload
    dataType: "script"
    add: (e, data) ->
      file = data.files[0]
        data.context = $("#button1").click( ->
          data.context = $(tmpl("template-upload", file))
          $('#new_avatar').append(data.context)
          data.submit()
        )
    progress: (e, data) ->
      if data.context
        progress = parseInt(data.loaded / data.total * 100, 10)
        data.context.find('.bar').css('width', progress + '%')

当文件上传开始时,我有这个脚本:

<script id="template-upload" type="text/x-tmpl">
  <div class="upload">
    {%=o.name%}
    <div class="progress">
      <div class="bar" style="width: 0%">
      </div>
    </div>
  </div>
</script>

我想我需要在文件上传脚本的add 部分添加一些内容,但我不确定是什么。感谢您的提示和建议:)

【问题讨论】:

    标签: javascript jquery ruby-on-rails jquery-file-upload


    【解决方案1】:

    您可以使用 file.name as 显示文件名

    alert(file.name + "Will start uploading")
    

    【讨论】:

    • 谢谢。听起来不错!我想在选择文件后显示进度条。当用户单击提交按钮时,现在显示进度条。你觉得我该怎么做?谢谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-27
    • 1970-01-01
    • 2014-11-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-12
    相关资源
    最近更新 更多