图像提交按钮传递值
我有一个像这样的图像提交按钮,
<input id="enter" name="enter" type="image"
value="Login"
src="images/btn_login.jpg"/>
一旦我单击该图像,我就会得到以下值
enter.x=39&enter.y=11
,但我想在提交时输入=登录
如何在提交时获取输入值作为登录?
谢谢
一些快速浏览器测试
Chrome: Working
Safari: Working
Firefox: Working
IE: Not Working
Opera: Not working
工作意味着输入=登录已通过。在撰写本文时所有浏览器均为最新版本
I have one image submit button like this
<input id="enter" name="enter" type="image"
value="Login"
src="images/btn_login.jpg"/>
once i click on this image i got following values
enter.x=39&enter.y=11
but i want to get enter=Login on submit
how to get enter value as login on submit?
Thanks
Some Quick browser tests
Chrome: Working
Safari: Working
Firefox: Working
IE: Not Working
Opera: Not working
Working means enter=login is passed. All browsers are at latest version at the time of writing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
IE6和IE7绝对不会传递图像提交的值,因此如果您希望页面在这些浏览器中运行,则不能使用此方法。然而,令我惊讶的是,你说最新版本的 IE 不起作用,我认为它起作用了
我发现的唯一可靠的后备是重载 name 属性:
然后,你必须迭代所有表单参数并查看对于名字以“enter”开头的人。请注意,您的输入仍然需要具有某种类型的 value 属性,否则浏览器根本不会传递它。
或者,您可以使用带有背景图像的普通提交按钮 - 很难获得一致的样式,或者使用
IE6 and IE7 definitely don't pass through the value of an image submit, so you can't use this method if you want your page to work in those browsers. However I'm surprised that you say the latest version of IE doesn't work, I thought it did
The only reliable fallback I've found is to overload the name attribute:
Then, you have to iterate through all the form params and look for one whose name starts with 'enter'. Note that your input still needs to have a value attribute of some kind, otherwise browsers won't pass it through at all.
Alternatively you can use a normal submit button with a background image - tricky to get consistently styled, or a
<button>
- although that has even more issues in IE than an image submit :(您可以使用一个小型 JavaScript,在单击图像并提交表单时将正确的值传递到隐藏的输入字段。
例子:
You can use a small javascript for this that passes the right value to a hidden input field on clicking the image and submit the form.
Example: