如何处理表单中的两个提交按钮?
我不明白这一点,
如果我这样做并单击结帐按钮,页面将不会转到结帐页面,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
只有当我将 name="checkout"
更改为 name="cart-checkout"
,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="cart-checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
它是这样工作的,但对我来说没有任何意义,你知道为什么这样做吗那样?
所以我尝试在
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out"><a href="checkout.php">Check out</a></button>
</form>
但是它是有效的 html< /strong> 将 标签放入
I don't understand this,
if I do this and I click the check out button, the page won't go to the check out page,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
It only does if I change the name="checkout"
to name="cart-checkout"
,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="cart-checkout" id="checkout" type="submit" value="Check out">Check out</button>
</form>
It works that way but does not make any sense to me, do you know why it does it that way?
So I tried to use <a>
tag inside the <button>
tag and it goes to the check out page,
<form action="cart.php" method="post" id="form-cart">
<button name="update" id="update" type="submit" value="Update cart">Update cart</button>
<button name="checkout" id="checkout" type="submit" value="Check out"><a href="checkout.php">Check out</a></button>
</form>
But does it a valid html to put <a>
tag inside the <button>
tag?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么不将按钮更改为:
然后在 PHP(在 cart.php 上)中,您可以执行以下操作:
Why not change the buttons to:
Then in PHP (on cart.php) you can do:
制作一个像
一样简单的
-编辑-
哎呀,抱歉,看错了。
What about making one
<button>
that simply acts like a<a href="">
?-edit-
Whoops, sorry, misread.
<button onclick="window.location='/nextpage';">
?实际上,我会在这里使用 JavaScript 和
onclick
事件,该事件会将您带到结账页面。I would actually use JavaScript here with an
onclick
event, which will take you to the checkout page.