您好我正在尝试让文件上传工作,但我不知道如何触发上传按钮。
我正在使用:https://github.com/kartik-v/yii2-widget-fileinput
我的代码:
<form class="form-horizontal form-label-left">
<div class="form-group">
<label class="control-label">Select File</label>
<input id="input-0a" class="file" type="file" data-allowed-file-extensions='["jpg", "png", "gif", "tiff", "bmp"]'>
</div>
</form>
和脚本:
<script type="text/javascript">
$(document).ready(function() {
// CATCH RESPONSE
$("#input-0a").on('fileloaded', function(event, file, previewId, index) {
alert('i = ' + index + ', id = ' + previewId + ', file = ' + file.name);
});
});
</script>
加载文件后,我获取所有数据。但是如何触发上传按钮呢?
答案 0 :(得分:1)
试试这个:
$("#input-0a").on('fileloaded', function(event, file, previewId, index) {
alert('i = ' + index + ', id = ' + previewId + ', file = ' + file.name);
$(this).closest('form').submit();
});
答案 1 :(得分:1)
你可以试试这个
$("#input-0a").fileinput({
uploadUrl: "url to upload",
}).on("filebatchselected", function (event, files) {
// trigger upload method immediately after files are selected
$("#input-0a").fileinput("upload");
});