我有一个提交输入更改的表单。 我已经在表单上添加了一个onsubmit事件来记录,如果提交发生了。 但它不记录我的提交。
下面是我的代码:
<label for="id_cover_picture">Upload Cover</label>
<form action="" method="get" id="change_cover_picture_form">
<input type="file" name="cover_pic" id="id_cover_picture" style="display: none;">
</form>
下面是我的JS代码:
<script>
const change_cover_picture_form = document.getElementById('change_cover_picture_form');
const form_cover_img = document.getElementById('id_cover_picture');
form_cover_img.addEventListener('input', () => {
console.log('input changed ...');
// even if it reloads , there will be data on localStorage
localStorage.setItem('input_change', 'input change ... cover image')
change_cover_picture_form.submit();
})
change_cover_picture_form.onsubmit = () => {
console.log('Form submitted ...');
// even if it reloads , there will be data on localStorage
localStorage.setItem('submit_cover', 'submitted ... cover image')
}
</script>
我正在记录输入更改并提交表单,但不记录提交。。。
请纠正我,如何确认提交,以及为什么onsubmit不工作。 我甚至尝试使用AddEventListener('submit')
预期答案:
记录提交,并在提交发生时执行一些操作
谢谢
没有办法提交表格。 向表单添加提交输入,然后单击该输入。