2016-04-22 66 views
1

此項目使用Twitter Bootstrap,頁面列出保存的文件以進行檢索或刪除。如果用戶點擊列表中的「下載」輸入按鈕,則其他文件的「下載」按鈕點擊不會被觸發。如何設置按鈕,以便用戶可以沿線下載每個文件?單擊列表中的引導程序輸入按鈕禁用其他按鈕

我已經嘗試將按鈕ID設置爲在下載腳本結束時啓用或激活,但是這並不奏效。有人看到這裏發生了什麼?提前致謝!

列表中查看:

<div class="panel panel-default" id="uploadPanel"> 
    <div class="panel-heading">Uploaded Files</div> 
    <div class="panel-body"> 
     <table id="dt_basic" class="table table-striped"> 
      <thead> 
       <tr> 
        <th style="display:none"></th> 
        <th class="text-center">File Name</th> 
        <th class="text-center">Uploaded Date</th> 
        <th class="text-center">Uploaded By</th> 
        <th></th> 
       </tr> 
      </thead> 
      <tbody> 
       @if (Model.UploadedFiles.Any()) 
       { 
        foreach (var record in Model.UploadedFiles) 
        { 
         <tr> 
          <td style="display:none">@record.UploadedFileID</td> 
          <td align="center">@record.UploadedFileName</td> 
          <td align="center">@String.Format("{0:d}", @record.UploadedFileDate)</td> 
          <td align="center">@record.UploadedBy</td> 
          <td align="center"><input type="button" class="btn btn-info" id="downloadFile" value="Download"> | <input type="button" class="btn btn-warning" id="deleteFile" value="Delete"></td> 
         </tr> 
        } 
       } 
      </tbody> 
     </table> 
    </div> 
</div> 

用於下載文件的腳本:

$("#downloadFile").click(function() { 
    var cells = $(this).closest('tr').children('td'); 
    var $id = Number(cells.eq(0).text()); 
    var $url = '@Url.Action("DownloadFile", "Files", new { id = "_id_" })'; 
    document.location.href = $url.replace("_id_", $id); 
    //Tried re-activating and re-enabling $("downloadFile") here, but to no avail 
}); 
+1

ID必須是唯一的,這就是爲什麼 – Vector

回答

3

通過class分配做它,而不是id

<td align="center"><input type="button" class="btn btn-info downloadFile" value="Download"> | <input type="button" class="btn btn-warning deleteFile" value="Delete"></td> 


$(".downloadFile").click(function() { 
    var cells = $(this).closest('tr').children('td'); 
    var $id = Number(cells.eq(0).text()); 
    var $url = '@Url.Action("DownloadFile", "Files", new { id = "_id_" })'; 
    document.location.href = $url.replace("_id_", $id); 
    //Tried re-activating and re-enabling $("downloadFile") here, but to no avail 
}); 
+0

美麗而簡單!謝謝@矢量! – jle

相關問題