![](/img/trans.png)
[英]Why by submitting a form with a link does not change the input text values?
[英]Form Submitting on input change, but does not log onsubmit event. How to check if input submitted or not?
我有一個提交輸入更改的表單。 如果提交發生,我已經在表單上添加了一個 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')
預期答案:
記錄提交,並在提交發生時執行一些操作
沒有辦法提交表格。 向表單添加提交輸入,然后單擊它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.