Perform Javascript action after reset button handles click

后端 未结 4 1036
天命终不由人
天命终不由人 2021-02-09 15:57

How do I perform an action immediately after an has already reset the form elements?

相关标签:
4条回答
  • 2021-02-09 16:36

    You always can use jQuery, or do some tricks with form reset event itself.

    0 讨论(0)
  • 2021-02-09 16:39

    Forms have a reset event that you can listen for.

    <script>
    function resetHandler() {
        // code
    }
    </script>
    <form ... onreset="resetHandler();">
    </form>
    

    Of course, it's bad practice to add javascript handlers this way, so you'd want to use .addEventListener/.attachEvent or jQuery.bind(), but you get the idea.

    0 讨论(0)
  • 2021-02-09 16:41

    Write code/events which you wanted to call in middle of this function. I have tested this. Working good.

    $(document).ready(function() {
        $("input:reset").click(function() {       // apply to reset button's click event
            this.form.reset();                    // reset the form
    
            // call your functions to be executed after the reset      
    
             return false;                         // prevent reset button from resetting again
        });
    });
    
    0 讨论(0)
  • 2021-02-09 16:53

    Try :

    <input type="reset" onclick="return resetForm();"/>
    
    function resetForm(){
        setTimeout(function(){
            // do whatever
        }, 50);
        return true;
    }
    
    0 讨论(0)
提交回复
热议问题