如何从 type="button" 的表单元素获取值
我在表单中有以下代码
<input type="button" name="nameofbutton" value="VALUE 1" onclick="javascript:if (confirm('Are you sure?')) {someSubmitFunction();}"/>
<input type="button" name="nameofbutton" value="VALUE 2" onclick="javascript:if (confirm('Are you sure??')) {someSubmitFunction();}"/>
当提交表单时,使用经典 ASP,我尝试使用 Request.Form("nameofbutton")
但没有得到任何值。谁能解释一下为什么吗?如果我将其更改为“提交”类型的按钮,它会起作用,但这意味着表单会提交两次。
谢谢
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为什么使用输入按钮来提交?
如果提交按钮的
onclick
(或者更好的是,表单的onsubmit
)返回 false,则提交将被取消。Why are you using input buttons to submit?
if the
onclick
of a submit button (or better yet, theonsubmit
of a form) returns false, then the submit is cancelled.@Janusz Jasinski:这对我有用;您会注意到,我故意将按钮的内容设置为
whatever
,当您提交表单时,value
属性的内容将显示。保存代码并亲自测试一下,这是一个工作示例。@Janusz Jasinski: This works for me; you'll notice I purposely made the contents of the buttons
what ever
, when you submit the form thevalue
attribute's contents will be shown. Save the code and test it out for yourself, it's a working sample.