[英]Call a function passing a file name from dynamically created table
我正在嘗試從動態創建的表中傳遞文件名並得到一些 Uncaught ReferenceError: Q1_58_English_Resume is not defined at HTMLAnchorElement.onclick (AddRequirement:1)
這里的文件名是“Q1_58_English_Resume”
動態表的腳本如下
if (filesData.length > 0) {
var table = '';
table += '<table class="radar-grid-table" id="TableAttach">';
table += '<thead>';
table += '<tr>';
table += '<th>Files</th>'
//table += '<th>Select</th>';
table += '<th>Actions</th>';
table += '</tr>';
table += '</thead>';
table += '<tbody>';
$.each(filesData, function (i, item) {
table += '<tr>';
table += '<td>' + item + '</td>';
//table += '<td title="' + item.AttachmentId + '">' + item.AttachmentId + '</td>';
//<input value="' + full.QuestionId + '
table += '<td> <a href="#" id="mylink" onclick="DownloadAttachment('+item+')">Download</a> </td>';
table += '</tr>';
});
table += '</tbody>';
table += '</table>';
return table;
}
Function 如下:
function DownloadAttachment(fileName) {
debugger;
var url = "/RequirementManagement/OpenFile?ids=" + fileName;
window.location.href = url;
}
試試這個,應該可以
var table = '';
table += '<table class="radar-grid-table" id="TableAttach">';
table += '<thead>';
table += '<tr>';
table += '<th>Files</th>'
//table += '<th>Select</th>';
table += '<th>Actions</th>';
table += '</tr>';
table += '</thead>';
table += '<tbody>';
$.each(filesData, function (i, item) {
table += '<tr>';
table += '<td>' + item + '</td>';
//table += '<td title="' + item.AttachmentId + '">' + item.AttachmentId + '</td>';
//<input value="' + full.QuestionId + '
table += '<td> <a href="#" id="mylink" onclick="DownloadAttachment('${item}')">Download</a> </td>';
table += '</tr>';
});
table += '</tbody>';
table += '</table>';
return table;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.