0

我有一个带有 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. 但是我无法使这段代码工作,甚至根本不会触发警报功能。我哪里做错了?

4

3 回答 3

4

有趣的小事,该remove()方法将在this对象上运行,将方法重命名为 _remove 或其他任何东西,它应该可以按预期工作。

于 2013-01-17T09:26:13.020 回答
0

尝试改变这个:

<button type="button" class="btn" onclick="javascript: remove();"><spring:message code="button.delete"/></button>

于 2013-01-17T09:23:09.430 回答
0
<html>
<head>
<title></title>
<script type="text/javascript">
function remove(){
    alert('test');
    var form = document.forms[0];
    form.action = "deleteRegistration";
    form.submit();
}
</script>
</head>
<body>
        <form id="registration-form" action="">
            <div class="form-actions">
                <button type="submit" class="btn btn-primary">submit</button>
                <button type="button" class="btn">something</button>
                <button type="button" class="btn" onclick="remove()">remove</button>
            </div>
        </form>
</body>
</html>
于 2013-01-17T09:30:49.913 回答