输入类型=图像名称和值不由ie和opera发送 [英] input type=image name and value not being sent by ie and opera
问题描述
当表单有多个图像输入并且服务器端使用它们的名称和/或值来区分哪个被点击时,它在FireFox中完美工作。但是,人们经常在发现HTML指定不需要发送任何内容之前编写整个内容,因此某些浏览器不会发送它。
它不是发送任何随机对象,而是发送一对作为 input_name = input_value
。这里最好的情况例子是我遇到的情况:所有元素都在一个表单中,并且所有元素都伴随着 name =deletevalue =< item_id>
我能做些什么来解决这个问题?
但它不允许获得值!
正确的答案是:
$ $ $('input [type = image]')
.unbind('mousedown')
.mousedown(function(){
$(this).after('< input type =hiddenname ='+ $(this)。 attr('name')+'value ='+ $(this).attr('value')+'/>');
});
这段代码在用户开始点击时会创建一个隐藏的输入副本。解绑('mousedown')是为了确保它只发生一次,即使你把代码放在一个奇怪的应用程序中的多个位置,它可能会被多次调用。
我建议把它放在 $(document).ready();
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.
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?
The problem was half solved up to now: like here
But it didn't allow to get the value!
The correct answer is:
$('input[type=image]')
.unbind('mousedown')
.mousedown(function(){
$(this).after('<input type="hidden" name="'+$(this).attr('name')+'" value="'+$(this).attr('value')+'" />');
});
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.
I recommend putting it in $(document).ready();
这篇关于输入类型=图像名称和值不由ie和opera发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!