我有一张很少提交的表格。一旦我提交表单,数据就会存储在数据库中,我将返回到同一页面。现在,如何在jsp ??
中清除表单中的字段<form class="form-horizontal col-lg-8" action="addDonationCamp" method="GET">
<div class="form-group">
<label for="location" class="col-sm-3 control-label">Location</label>
<div class="col-sm-8">
<input type="text" name="location" class="form-control" id="location" placeholder="Location" value="${fn:escapeXml(param.location)}">
<label class="errorColor">${message.location}</label>
</div>
</div>
<div class="form-group">
<div class="form-group">
<label for="description" class="col-sm-3 control-label">Description</label>
<div class="col-sm-8">
<div class="form-group">
<div class="col-sm-offset-5 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
答案 0 :(得分:1)
每次重置都不会重置所有字段。
如果您使用纯Javascript,
,您可以拥有类似的内容var formElements = document.getElementById("myForm").elements;
var fieldType = "";
for (i = 0; i < formElements.length; i++)
{
fieldType = formElements[i].type.toLowerCase();
switch (fieldType)
{
case "text":
case "password":
case "textarea":
case "hidden":
formElements[i].value = "";
break;
case "radio":
case "checkbox":
if (formElements[i].checked)
{
formElements[i].checked = false;
}
break;
default:
break;
}
}
答案 1 :(得分:0)