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

前端 未结 16 1305
清酒与你
清酒与你 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:51

    You can use the following.

    @using (Html.BeginForm("MyAction", "MyController", new { area = "MyArea" }, FormMethod.Post, new { @class = "" }))
    {
    
    @Html.LabelFor(m => m.MyData, new { @class = "col-form-label" })
    @Html.TextBoxFor(m => m.MyData, new { @class = "form-control" })
    }

    Then clear the form:

        $('.btn:reset').click(function (ev) {
            ev.preventDefault();
            $(this).closest('form').find("input").each(function(i, v) {
                $(this).val("");
            });
        });
    

提交回复
热议问题