【发布时间】:2019-12-22 17:23:09
【问题描述】:
当用户更改他们从 <select> 元素中选择的选项时,我希望能够更改 Dropzone 元素的 acceptedFiles 选项。有点像这段代码Dropzone.options.myDropzone = { acceptedFiles: selected_value};
到目前为止,我已经尝试了两种方法:
HTML 选择框:
<select class="form-control" id="cond_file_type" name="cond_file_type">
<option>-- File Type --</option>
<option value="pdf">PDF</option>
<option value="docx">DOCX</option>
<option value="xlsx">XLSX</option>
<option value="png">PNG</option>
<option value="jpg">JPG</option>
<option value="gif">GIF</option>
</select>
Javascript:
// Attempt 1
document.getElementById("cond_file_type").onchange = function(){
var file_type = '.' + this.options[this.selectedIndex].value;
Dropzone.options.myDropzone = {
acceptedFiles: file_type,
};
};
// Attempt 2
var file_type = '';
document.getElementById("cond_file_type").onchange = function () {
file_type = '.' + this.options[this.selectedIndex].value;
};
Dropzone.options.myDropzone = {
acceptedFiles: file_type,
};
我尝试了 1 和 2,但它们都不起作用。
【问题讨论】:
标签: javascript dropzone.js dropzone