How to reset a form using jQuery with .reset() method

前端 未结 16 1194
清酒与你
清酒与你 2020-11-22 17:28

I had working code that could reset my form when I click on a reset button. However after my code is getting longer, I realize that it doesn\'t work anymore.



        
16条回答
  •  心在旅途
    2020-11-22 17:42

    jQuery does not have reset() method; but native JavaScript does. So, convert the jQuery element to a JavaScript object by either using :

    $("#formId")[0].reset();
    
    $("#formId").get(0).reset();
    

    We may simply use Javascript code

    document.getElementById("formid").reset();
    

提交回复
热议问题