输入类型=图像名称和值不由ie和opera发送 [英] input type=image name and value not being sent by ie and opera

查看:134
本文介绍了输入类型=图像名称和值不由ie和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屋!

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