我有一个带有 3 个按钮的HTML表单:
<html:form modelAttribute="registration" id="registration-form" formUrl="/registrationForm">
<input type="hidden" name="id"/>
<html:field name="voucherID" labelCode="label.voucherID" type="text"/>
<html:field name="programID" labelCode="label.programID" type="text"/>
<html:field name="quantity" labelCode="label.quantity" type="text"/>
<html:field name="active" labelCode="label.active" type="checkBox"/>
<div class="form-actions">
<button type="submit" class="btn btn-primary"><spring:message code="button.add"/></button>
<button type="reset" class="btn"><spring:message code="button.cancel"/></button>
<button type="button" class="btn" onclick="remove()"><spring:message code="button.delete"/></button>
</div>
</html:form>
Javascript:
<head>
<%@ include file="header.jsp"%>
<title><spring:message code="title.registration"/></title>
<script type="text/javascript">
function remove(){
alert('test');
var form = document.forms[0];
form.action = "deleteRegistration";
form.submit();
}
</script>
</head>
我想要做的是,每当用户按下删除按钮时,它应该将 action 的值更改为deleteRegistration
. 但是我无法使这段代码工作,甚至根本不会触发警报功能。我哪里做错了?