1. 程式人生 > 其它 >jquery 上傳附件的相關程式碼

jquery 上傳附件的相關程式碼

function setUploadFileMethod() {
    var fileList = Cyan.Arachne.form.preWorkDtoList;
    refactorUploadFileMethod(fileList, 'uploadFiles_', 'inputFile', 'uploadForm_');
}

/**
 * 設定附件上傳的按鈕事件
 *
 * @param fileList 列表的資料
 * @param uploadButtonName 上傳檔案的按鈕id
 * @param fileInputName    上傳檔案的輸入框id
 * @param uploadFormName   上傳檔案對應的form名稱
 
*/ function refactorUploadFileMethod(fileList, uploadButtonName, fileInputName, uploadFormName) { for (var i = 0; i < fileList.length; i++) { $('#' + uploadButtonName + i).bind("click", {index: i}, function (ti) { var t = ti.data.index; $('#' + fileInputName + t).click(); }); $(
'#' + fileInputName + i).bind("change", {index: i, uploadFormName: uploadFormName + i}, saveFileInfos2); } } function saveFileInfos2(event) { var result = saveFileProcess(null, event.data.uploadFormName); saveFileInfos2(result); } function saveFileProcess(attachmentId, uploadFormName) { saveFile(attachmentId,
0, { callback: function (ret) { if (ret !== null) return ret; else return null; }, wait: true, progress: true, form: $('#' + uploadFormName)[0].name }) } // 上傳檔案的介面 function saveFile2(attachmentId, index) { Cyan.Arachne.doPost("/emphasisJob/project/report/service/saveFileInfo?attachmentId=" + attachmentId + "&fileIndex=" + index, arguments, 3); }