Как запустить один и тот же скрипт независимо на нескольких элементах onclick на одной странице

У меня есть следующий скрипт, который запускается при нажатии на <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>&nbsp;</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

Решение

Попробуйте использовать массив в атрибуте name, поэтому вместо name = «file» do name = «file []», вы можете получить доступ к каждому файлу соответственно, не переопределяя.

0

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector