按钮文本与在查询字符串中提交的值不同 [英] Button text different than value submitted in query string

查看:76
本文介绍了按钮文本与在查询字符串中提交的值不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让我的表单的按钮标签文本与提交给服务器的值不同 / i>使用<按钮> 标签?



长版本:



我想让表单中按钮上显示的文本与查询字符串中提交的值不同。所以,我环顾四周,并遇到了这种方法......

 < button name =methodtype =submit value =重新打包>更新配置< /按钮> 

...并且在我的笔记本电脑上的IE9上工作,我很高兴。用户看到更新配置,服务器收到查询字符串中的 method = repackage

然后我带来了这个应用程序工作,并运行在工作站上,也与IE9。但有些事情出错了。用户仍然看到更新配置,但服务器现在在查询字符串中收到了 method = Update%20Config



<所以我调查了一些。我发现www.w3schools.com建议不要在表单中使用< button> 标签。他们说:如果你在HTML表单中使用<按钮> 元素,不同的浏览器可能会提交不同的值,使用< input> / code>在HTML表单中创建按钮,位于这篇文章。这似乎是我所经历的。



所以我看了更多,发现了很多关于正确方法的冲突信息。例如这里是一个Stack Overflow帖子,它精确地询问了这个问题,但是接受的答案是使用<按钮> 标签。我可以从经验和研究中得知,这不是一种可靠的方法。

解决方案

如果没有其他方法, p>

使用图片按钮,而不是按钮。图像按钮可以像普通的提交按钮一样工作,但是您可以创建所需按钮文本的图像(然后没有人可以更改文本)。

 < input type =imagesrc =http://images.webestools.com/buttons.php?frm=2&btn_type=31&txt=Update+Configname =methodvalue = 重新打包 > 


Short version:

How can I have my form's button label text differ from the value submitted to the server without using the <button> tag?

Long version:

I wanted to have the text that appeared in a button in a form to be different than the value submitted in the query string. So, I looked around, and came across this approach...

<button name="method" type="submit" value="repackage">Update Config</button>

...and that worked on IE9 on one of my laptops and I was happy. The user saw "Update Config" and the server received method=repackage in the query string.

Then I brought this app to work and ran it on a workstation, also with IE9. But something had gone wrong. The user still saw "Update Config", but the server now received method=Update%20Config in the query string.

So I investigated some more. I found that www.w3schools.com recommmended not using a <button> tag in a form. They say: "If you use the <button> element in an HTML form, different browsers may submit different values. Use <input> to create buttons in an HTML form" in this article. This seems to be what I am experiencing.

So I looked some more, and found lots of conflicting information about the right way to do this. For example here is a Stack Overflow post that asks exactly this question, but the accepted answer is to use the <button> tag. I can say from experience and research that this is not a reliable approach.

解决方案

If there's no other way try this:

Use an image button, instead of button. An image button will work as ordinary submit button, but you create an image of the desired button text (no one can change your text then).

 <input type="image" src="http://images.webestools.com/buttons.php?frm=2&btn_type=31&txt=Update+Config" name="method" value="repackage">

这篇关于按钮文本与在查询字符串中提交的值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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