Clearing my form inputs after submission

前端 未结 9 943
Happy的楠姐
Happy的楠姐 2020-11-30 04:25

I\'ve tried it a few different ways based on searches I\'ve done on the subject and for some reason I can\'t get it to work. I just want my text inputs and textarea to clear

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-30 04:37

    var btnClear = document.querySelector('button');
    var inputs = document.querySelectorAll('input');
     
    btnClear.addEventListener('click', () => {
        inputs.forEach(input =>  input.value = '');
    });
    

提交回复
热议问题