我正在使用fileinput.js功能于 Jasny Bootstrap
我的目标是让我的表单在用户选择文件后自动提交。我不希望他们必须点击“提交”。
到目前为止,我已经尝试了 JavaScript和 jQuery解决方案。当不使用 Jasny 的 fileinput.js 时,这两种解决方案都可以很好地工作,但当我使用它时,它们就不起作用了。
document.getElementById("file").onchange = function() {
document.getElementById("form").submit();
};
--
$('#file').change(function() {
$('#form').submit();
});
使用Jasny的fileinput.js时,如何让用户选择文件后表单自动提交?
最佳答案
来自Usage section in the docs和 source ,看起来您需要监听自定义 change.bs.fileinput
事件而不是 native change
事件。尝试这样的事情:
$('#file').on('change.bs.fileinput', function () {
$('#form').submit();
});
关于javascript - 在 Jasny Bootstrap 中使用 fileinput.js 时,选择文件后自动提交表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22438890/