Javascript 在Jasny Bootstrap中使用fileinput.js时,在选择文件后自动提交表单
我正在使用中的功能 我的目标是让我的表单在用户选择文件后自动提交。我不希望他们必须点击“提交” 到目前为止,我已经尝试了两种方法和解决方案。这两种解决方案在不使用Jasny的fileinput.js时都能很好地工作,但在我使用它时却不能工作Javascript 在Jasny Bootstrap中使用fileinput.js时,在选择文件后自动提交表单,javascript,jquery,forms,twitter-bootstrap,jasny-bootstrap,Javascript,Jquery,Forms,Twitter Bootstrap,Jasny Bootstrap,我正在使用中的功能 我的目标是让我的表单在用户选择文件后自动提交。我不希望他们必须点击“提交” 到目前为止,我已经尝试了两种方法和解决方案。这两种解决方案在不使用Jasny的fileinput.js时都能很好地工作,但在我使用它时却不能工作 document.getElementById("file").onchange = function() { document.getElementById("form").submit(); }; -- 当用户使用Jasny的fileinput
document.getElementById("file").onchange = function() {
document.getElementById("form").submit();
};
--
当用户使用Jasny的fileinput.js选择文件后,如何使表单自动提交?从和中,您似乎需要侦听自定义change.bs.fileinput
事件,而不是本机change
事件。试着这样做:
$('#file').on('change.bs.fileinput', function () {
$('#form').submit();
});
$('#file').on('change.bs.fileinput', function () {
$('#form').submit();
});