我有以下观点: -
<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
答案 0 :(得分:3)
尝试重置表单:
$('#partialWrapper form')[0].reset();