单击<input type="button" class="button" value="Start Upload" onclick="upload()" />
按钮时,我运行以下脚本。我需要帮助尝试找出如何独立于多个onclick元素来运行同一脚本来上传文件。此时,如果我在输入字段1上上传文件,然后尝试在输入字段2上上传文件,则输入字段2的上传将覆盖输入字段1的上传。
<script>
bigUpload = new bigUpload();
//The id of the file input
bigUpload.inputField = 'file';
//The id of the progress bar
//Width of this element will change based on progress
//Content of this element will display a percentage
//See bigUpload.progressUpdate() to change this code
bigUpload.progressBarField = 'progressBarFilled';
//The id of the time remaining field
//Content of this element will display the estimated time remaining for the upload
//See bigUpload.progressUpdate() to change this code
bigUpload.timeRemainingField = 'timeRemaining';
//The id of the text response field
//Content of this element will display the response from the server on success or error
bigUpload.responseField = 'uploadResponse';
//Size of file chunks to upload (in bytes)
//Default: 1MB
bigUpload.chunkSize = 1000000;
//Max file size allowed (in bytes)
//Default: 2GB
bigUpload.maxFileSize = 2147483648;
function upload() {
bigUpload.resetKey();
bigUpload.processFiles();
}
function abort() {
bigUpload.abortFileUpload();
}
</script>
<div id="bigUpload">
<div class="container">
<form>
<input type="file" name="file" id="file" />
<input type="button" class="button" value="Start Upload" onclick="upload()" />
<input type="button" class="button abort" value="Cancel" onclick="abort()" />
</form>
<div id="progressBarContainer">
<div id="progressBarFilled">
</div>
<div id="timeRemaining"></div>
</div>
<div id="uploadResponse"></div>
</div>
</div>
<div> </div>
<div id="bigUpload">
<div class="container">
<form>
<input type="file" name="file" id="file" />
<input type="button" class="button" value="Start Upload" onclick="upload()" />
<input type="button" class="button abort" value="Cancel" onclick="abort()" />
</form>
<div id="progressBarContainer">
<div id="progressBarFilled">
</div>
<div id="timeRemaining"></div>
</div>
<div id="uploadResponse"></div>
</div>
</div>
答案 0 :(得分:0)
尝试在name属性中使用数组,因此可以使用name =“ file []”代替name =“ file”来访问每个文件,而不会覆盖。