简体   繁体   English

使 html 按钮不会触发 node.js 中的 app.post

[英]make html buttons not trigger an app.post in node.js

I am using app.post to redirect the user.我正在使用 app.post 重定向用户。 when the user presses the first button, I do not want them to be redirected, but i still want the first button to send the value.当用户按下第一个按钮时,我不希望它们被重定向,但我仍然希望第一个按钮发送值。 I cant put the <form> above the first button, so how do i make the first button not trigger the app.post.我不能将<form>放在第一个按钮上方,那么如何让第一个按钮不触发 app.post。

You can add attribute type="button" to button tag to remove this behavior.您可以向按钮标记添加属性 type="button" 以删除此行为。 Example:例子:

<form action="/" method="post">
  First name: <input type="text" name="fname">

  <button>I'll submit form</button>
  <button type="submit">I'll submit form too</button>
  <button type="button">I'm just a button so I don't submit anything</button> <-- It's work
</form>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM