简体   繁体   English

从IE中的输入“上”

[英]Getting “on” from input in IE

Here is the problem I have an app that is working in every browser but IE(8). 这是我有一个可以在除IE(8)之外的所有浏览器中运行的应用程序的问题。 Its a simple form that is filled with data from ajax requests. 它是一种简单的形式,充满了来自ajax请求的数据。 At the bottom there is a button that sends the data to the server and gets a generated query. 在底部有一个按钮,用于将数据发送到服务器并获取生成的查询。

The problem is, at IE when the user presses the query button, the browser sends all checkbox or radiobutton values as the string "on" although the value attribute is clearly different from "on". 问题是,在IE上,当用户按下查询按钮时,浏览器会将所有复选框或单选按钮值作为字符串“ on”发送,尽管value属性明显不同于“ on”。

Why is that happening? 为什么会这样呢?

I am using java and spring mvc(version 3). 我正在使用java和spring mvc(版本3)。

I haven't attached any code because I am not even sure what section of code could be useful. 我没有附加任何代码,因为我什至不确定哪一段代码会有用。 Also the application is medium size so, I'm going to post code snippets on demand. 另外,应用程序的大小适中,因此,我将按需发布代码段。

[Edit] Using developer tools I was able to find that the value is being passed correctly but just after the input is set, its value becomes "on". [编辑]使用开发人员工具,我能够正确地传递值,但是在设置输入之后,它的值就变为“ on”。 I checked that with javascript generated inputs. 我用javascript生成的输入进行了检查。 For the ones that are loaded, I do not know why they are set that way. 对于已加载的那些,我不知道为什么要这样设置。

Here is a small snippet of that DOM generation: 这是该DOM的一小段代码:

 var cell = $("<td/>").append(
        $("<input/>")
        .attr("id", lista[i].codigo+"RadioVariavel")
        .attr("name", "consulta.variavel")
        .attr("value", lista[i].codigo)
        .attr("type", "radio")
        ).append(
        $("<label/>")
        .attr("for", lista[i].codigo+"RadioVariavel")
        .html(lista[i].descricao)
        );

I've run into a similar problem before. 我以前也遇到过类似的问题。 I'm suprised that you are not getting an outright error, because jQuery doesn't allow you to change the input type . 我很惊讶您没有得到一个彻底的错误,因为jQuery不允许您更改输入类型

Try this instead: 尝试以下方法:

$('<input type="radio" />')
    .attr("id", lista[i].codigo+"RadioVariavel")
    .attr("name", "consulta.variavel")
    .attr("value", lista[i].codigo);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM