我遇到问题,我互相嵌套提交,外部提交按钮不起作用。有我的代码:
<div class="container">
<form method="POST" action="/types">
<div>
<ul>
<% data.movementNames.forEach(function(movnames) { %>
<li>
<input id="movnames" type="text" name="movname" value=<%=movnames.movementName%> />
<form style="display: inline" class="pull-right" action="/types/movementname/<%=movnames._id%>?_method=DELETE" method="POST">
<button class="btn btn-xs btn-danger">DELETE</button>
</form>
</li>
<% }); %>
</ul>
<div id="newMovementNamePlaceholder">
</div>
<a type='button' onclick="addnewMovementName()" id="newMovementNameButton">Add Round</a>
</div>
<div>
<ul>
<% data.wodtypes.forEach(function(wodytype) { %>
<li>
<input id="wodytype" type="text" name="wodytype" value=<%=wodytype.wodType%> />
<form style="display: inline" class="pull-right" action="/types/wodtype/<%=wodytype._id%>?_method=DELETE" method="POST">
<button class="btn btn-xs btn-danger">DELETE</button>
</form>
</li>
<% }); %>
</ul>
<div id="newWodTypePlaceholder">
</div>
<a type='button' onclick="addnewWodType()" id="newWodTypeButton">Add Round</a>
</div>
<div>
<ul>
<% data.workoutType.forEach(function(workouttype) { %>
<li>
<input id="workouttype" type="text" name="workouttype" value=<%=workouttype.workoutType%> />
<form style="display: inline" class="pull-right" action="/types/workouttype/<%=workouttype._id%>?_method=DELETE" method="POST">
<button class="btn btn-xs btn-danger">DELETE</button>
</form>
</li>
<% }); %>
</ul>
<div id="newWorkoutTypePlaceholder">
</div>
<a type='button' onclick="addnewWorkoutType() ">Add Round</a>
</div>
<input type="submit" value="Submit" />
</form>
</div>
并且按钮点击后应该触发的方法如下所示(仅用于测试目的):
typesRoute.post("/types", async (req: any, res: any) => {
await console.log("req.body");
await console.log(req.body);
await console.log("req.params");
await console.log(req.params);
renderIndexPage(res);
});
我为此使用ExpressJS和TypeScript。但我认为这是纯HTML问题。 你可以在那里找到完整的代码:https://github.com/BenceUszkai/crossfitnote/tree/typesRoute 你有什么建议来修复我破损的代码吗? (我知道这是一个微不足道的问题)