我如何在我的asp.net mvc应用程序中使用Jquery重置Div元素中的所有字段值

时间:2012-03-04 22:25:04

标签: asp.net-mvc-3 jquery

我有以下观点: -

<div id = "partialWrapper">
 @using (Ajax.BeginForm("Create", "Answer", new AjaxOptions
{
    HttpMethod = "Post",
    InsertionMode = InsertionMode.InsertAfter,
    UpdateTargetId = "incrementanswer",
    OnSuccess = "removePartial"
}))

 {
     <div id = "returnedquestion">
     @Html.ValidationSummary(true)

    <fieldset> 
        <legend>Answer here</legend> 
        <div class="editor-label"> 
            @Html.LabelFor(model => model.Description) 
        </div> 
        <div class="editor-field"> 
            @Html.EditorFor(model => model.Description) 
            @Html.ValidationMessageFor(model => model.Description) 
        </div> 
        <div class="editor-label"> 
            @Html.LabelFor(model => model.IsRight) 
        </div> 
        <div class="editor-field"> 
             @Html.DropDownList("IsRight", String.Empty) 
            @Html.ValidationMessageFor(model => model.IsRight) 
        </div>  
    </fieldset> 
     <input type= "hidden" name = "questionid" value = @ViewBag.questionid>
     <input type= "hidden" name = "assessmentid" value = @ViewBag.assessmentid>
     <input type="submit" value="Add answer" />
 </div>
 }
 </div>

我想清除字段中的所有数据,以便用户可以轻松添加新对象,我尝试了以下操作,但这些将删除文本和字段: -

function removePartial() {
    $("#partialWrapper").remove();
} 

function removePartial() {
    $("#partialWrapper").empty();
} 

有没有办法清除Div中所有字段内的文本而不删除字段。 BR

1 个答案:

答案 0 :(得分:3)

尝试重置表单:

$('#partialWrapper form')[0].reset();