2013-06-20 44 views
0

簡單的問題,但答案很複雜。我正在使用BluImp JQuery File-Uploader。我已經定製了這些模板,以便一個名字很長的文件不會弄亂我網頁的外觀。這是我用來做這件事的代碼的一個例子。JQuery模板引擎在Chrome,Safari,Firefox中一半工作

<!-- The template to display files available for upload --> 
<script id="template-upload" type="text/x-tmpl"> 
    {% for (var i=0, file; file=o.files[i]; i++) { %} 
    {% if (file.name.length > 16) file.name = file.name.substring(0, 16) + "..."; %} 
     <tr class="template-upload fade"> 
      <td class="name"><span>{%=file.name%}</span></td> 
      {% if (file.error) { %} 
       <td class="error" colspan="2"><span class="label label-important">Error</span> {%=file.error%}</td> 
      {% } else if (o.files.valid && !i) { %} 
       <td> 
        <div class="progress progress-success progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0"><div class="bar" style="width:0%;"></div></div> 
       </td> 
       <td>{% if (!o.options.autoUpload) { %} 
        <button class="btn btn-primary start"> 
         <i class="icon-upload icon-black"></i> 
         <span>Start</span> 
        </button> 
       {% } %}</td> 
      {% } else { %} 
       <td colspan="2"></td> 
      {% } %} 
      <td>{% if (!i) { %} 
       <button class="btn btn-warning cancel"> 
        <i class="icon-ban-circle icon-black"></i> 
        <span>Cancel</span> 
       </button> 
      {% } %}</td> 
     </tr> 
    {% } %} 
</script> 
<!-- The template to display files available for download --> 
<script id="template-download" type="text/x-tmpl"> 
    {% for (var i=0, file; file=o.files[i]; i++) { %} 
    {% if (file.name.length > 16) file.name = file.name.substring(0, 16) + "..."; %} 
     <tr class="template-download fade"> 
      {% if (file.error) { %} 
       <td></td> 
       <td class="name"><span>{%=file.name%}</span></td> 
       <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> 
       <td class="error" colspan="2"><span class="label label-important">Error</span>{%=file.error%}</td> 
      {% } else { %} 
       <td class="name"> 
       {%=file.name%} 
       </td> 
       <td class="size"><span>{%=o.formatFileSize(file.size)%}</span></td> 
       <td colspan="1"></td> 
      {% } %} 
      <td width="130px;"> 
       <button class="btn btn-danger delete" data-type="{%=file.delete_type%}" data-url="{%=file.delete_url%}"{% if (file.delete_with_credentials) { %} data-xhr-fields='{"withCredentials":true}'{% } %}> 
        <i class="icon-trash icon-black"></i> 
        <span>Delete</span> 
       </button> 
       <input type="checkbox" name="delete" value="1" class="toggle"> 
      </td> 
     </tr> 
    {% } %} 
</script> 

file.name格式化始終在IE中工作。在所有其他瀏覽器中,只有下載模板有效。 I.E.文件名稱僅在文件上傳完成後才被修剪。那麼,如何在上傳其他瀏覽器之前將文件名縮減?

+0

的E w!我會幫忙,但我不想讓模板腳本在我手上! – SpYk3HH

回答

0

使用正則表達式來手動修剪它,如以下到Windows路徑:

.replace(/[^\\]+\\/g,""); 
相關問題