输入类型=图像名称和值未被 ie 和 opera 发送 [英] input type=image name and value not being sent by ie and opera
问题描述
当一个表单有多个图像输入并且服务器端使用它们的名称和/或值来区分哪个被点击时,它在 FireFox 中完美地工作.然而,人们经常在发现 HTML 规定不需要发送任何内容之前写了整个内容,因此某些浏览器不发送它.
When a form has multiple image inputs and the server side uses their names and/or values to distinguish which one was clicked, it works perfectly in FireFox. However, people often write the whole thing before finding out that HTML specifies that nothing has to be sent, and thus some browsers are not sending it.
这不是关于发送任何随机对象,而是发送一对作为input_name=input_value
.这里最好的最坏情况示例是我遇到的:一个元素列表,所有元素都在一种形式中,并且都带有带有 name="delete" value="<item_id>"
的按钮
It's not about sending any random object, but sending a pair as input_name=input_value
. The best worst-case scenario example here would be what I've encountered: A list of elements all in one form and all accompanied by buttons with name="delete" value="<item_id>"
我该怎么做才能解决这个问题?
What can I do to fix this problem?
推荐答案
问题到此解决一半:像这里
但是它不允许获取值!
正确答案是:
$('input[type=image]')
.unbind('mousedown')
.mousedown(function(){
$(this).after('<input type="hidden" name="'+$(this).attr('name')+'" value="'+$(this).attr('value')+'" />');
});
当用户开始点击输入时,此代码会创建一个隐藏的输入副本.unbind('mousedown') 是为了确保它发生一次,即使您将代码放在一个奇怪的应用程序中的多个位置并且可能会被多次调用.
This code creates a hidden duplicate of the input when user starts clicking it. The unbind('mousedown') is to secure it happens once even if You put the code in multiple places in a weird application and it might be called more than once.
我建议把它放在 $(document).ready();
这篇关于输入类型=图像名称和值未被 ie 和 opera 发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!