如何使用jQuery重置我的Ajax.Begin表单字段值

时间:2014-07-11 10:34:45

标签: javascript jquery razor

我的asp.net mvc razor视图中有以下Ajax.BeginForm: -

    <div id="searchform">                           

    @using (Ajax.BeginForm("AdvanceSearchIndexByName","Home", 
    new AjaxOptions
    {
        HttpMethod = "get",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "progress2",
        UpdateTargetId = "SearchTable2"
    }))
    {
       }
<input class="btn btn-success" type="submit" value="Clear" id="clear" />

我编写了以下javaScript: -

<script type="text/javascript">

    $("#clear").on('click', function () {
        alert('2');
        $('#searchform').clear();
});
        </script>

单击“清除”按钮时重置表单值,但是当前清除按钮不会有任何影响。任何建议? 感谢

1 个答案:

答案 0 :(得分:3)

您可以在没有任何JavaScript的情况下执行此操作,只需添加reset type button

即可
 @using (Ajax.BeginForm("AdvanceSearchIndexByName","Home", 
    new AjaxOptions
    {
        HttpMethod = "get",
        InsertionMode = InsertionMode.Replace,
        LoadingElementId = "progress2",
        UpdateTargetId = "SearchTable2"
    }))
 {
        <input type="reset" value="reset"/>

 }