在选择中添加选项并在Internet Explorer上选择一个选项 [英] Adding options to a select and selecting one on internet explorer

查看:74
本文介绍了在选择中添加选项并在Internet Explorer上选择一个选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个选择,我正在使用javascript填充选项。类似

I have a select, and I am filling the options using javascript. Something like

    var select = document.getElementById("selectBox");

    for (var i = 0; i < data.length; i++) {
        var option = document.createElement("option");
        option.innerHTML = data[i].name;
        option.value = data[i].id;
        select.appendChild(option);
    }

它适用于Firefox和Chrome,但不适用于Internet Explorer。当我检查IE上生成的html时,我看到

It works fine on Firefox and Chrome, but not on Internet Explorer. When I check the html generated on IE I see

    <select id="selectBox"/>

我可以做些什么让它在IE上工作吗?

Is there something I can do for it to work on IE?

编辑
刷新开发工具的html页面后(IE在html更改后没有这样做)我看到已经添加了选项,但是那里似乎是分配值的问题,我正在使用

EDIT After refreshing the html page on development tools(IE doesn't do this after the html change) I see that the options have been added, but there seems to be a problem assigning the value, I'm using

select.value = theValue;


推荐答案

问题在于我从中获取所选值。我正在使用ajax调用,IE(我认为)缓存了响应。当我改变一些值时,服务器必须给我正确的选择选项,但它给了我一个错误,因为IE总是在读相同的答案。

The problem was where I was getting the selected value from. I was using ajax calls, and IE was (I think) caching the response. When I changed some value, the server had to give me the correct select option, but it was giving me wrong one since IE was always reading the same answer.

这篇关于在选择中添加选项并在Internet Explorer上选择一个选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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