最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

按钮不提交表单但提交值

运维笔记admin13浏览0评论

按钮不提交表单但提交值

按钮不提交表单但提交值

我想要一个不提交表单的按钮,但确实提交了它的价值。例如,

<html>
 <body>
  <form action="/home" method="post">
   <button value="1" type="button" name="b1>Test</button>
   <button value="2" type="submit" name="b2">Test2</button>
  </form>
 </body>
</html>

当我按下第一个,它不会提交表格,但它会提交其价值。在node.js中,我将拥有。

app.post('/home', (req, res) => {
 var button1 = req.body.b1;
 var button2 = req.body.b2;
 console.log(button1);
 console.log(button2);
});

当我按下按钮1时,它不会提交任何内容,也不会重定向您。当你按下button2时,它将重定向你,并将console.log同时按钮1和按钮2。

回答如下:

也许一个隐藏的输入会做到这一点?

 <input value="1" type="hidden" name="b1>

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论