Is it possible to clear a form and reset (reload) the page with one button?

前端 未结 4 1248
一生所求
一生所求 2020-12-31 08:11

I\'ve got a form on a page where the user types something in and then a result is returned and displayed on the page. Is it possible for me to have a button that will both,

4条回答
  •  一向
    一向 (楼主)
    2020-12-31 08:38

    using JQuery, do something like this on the page;

    $(document).ready(function () {
        resetForms();
    });
    
    function resetForms() {
        for (i = 0; i < document.forms.length; i++) {
            document.forms[i].reset();
        }
    }
    

    and then just use your second input, forms will auto refresh when the page loads back up.

提交回复
热议问题