Clear form fields with jQuery

前端 未结 30 3280
甜味超标
甜味超标 2020-11-22 15:48

I want to clear all input and textarea fields in a form. It works like the following when using an input button with the reset class:

$(\".reset         


        
30条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 16:34

    Tested and verified code:

      $( document ).ready(function() {
        $('#messageForm').submit(function(e){
           e.preventDefault();
        });
        $('#send').click(function(e){
          $("#messageForm")[0].reset();
        });
      });
    

    Javascript must be included in $(document).ready and it must be with your logic.

提交回复
热议问题