HTML表单:如何添加传递不同值的多个按钮? [英] HTML Forms: How do I add multiple buttons that pass different values?

查看:191
本文介绍了HTML表单:如何添加传递不同值的多个按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个允许发布新闻的脚本。我希望能够在发布按钮旁边创建另存为草稿按钮。我怎样才能允许另存为草稿按钮传递一个值到后端?

我只需要一个简单的1或0取决于哪个按钮被按下,

解决方案

 < input type =submit name =saveasdraftvalue =另存为草稿> 
< input type =submitname =savevalue =Save>

然后您就可以检测到后端按了哪个按钮的名称。被按下的那个将出现在提交的表单域中。其他人不会。


I have a script that allows the posting of news. I want to be able to create a 'save as draft' button next to the 'publish' button. How can I allow the 'save as draft' button to pass a value to the back end?

I just need a simple 1 or 0 depending on which button was pressed, I'm using php by the way.

解决方案

<input type="submit" name="saveasdraft" value="Save as Draft">
<input type="submit" name="save" value="Save">

And then you can detect which button was pressed at the backend by their name. The one that was pressed will be present in the submitted form fields. The others won't be.

这篇关于HTML表单:如何添加传递不同值的多个按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆