选择未在IE中显示的选项 [英] Select options not showing in IE

查看:94
本文介绍了选择未在IE中显示的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些选项的动态生成选择,它在普通浏览器中显示选项很好,但在IE中它是空的选项。这是生成的HTML:

I have a dynamically generated select with some options and it shows the options fine in normal browsers, but its empty options in IE. Here's the generated HTML:

<select name="0" id="custom_0" style="border-bottom: #c0cedb 1px solid; border-left: #c0cedb 1px solid; background-color: #ededed; width: 280px; font-size: 0.87em; border-top: #c0cedb 1px solid; border-right: #c0cedb 1px solid">
    <option id="1000" value="0" name="00">1x2GB ECC DDRIII 2GB ECC DDRIII</option>
    <option id="1001" value="10" name="01">2x2GB ECC DDRIII 4GB ECC DDRIII (+10.00 €)</option>
</select>

我无法真正向您展示javascript,因为它有很多,我可以使演示变得简单。也许你有一些人会有类似的经历,可以想出这一个。谢谢

I can't really show you the javascript, since there's so much of it and I would be able to make it simple just for a demo. Maybe you had some of you would've had a similar experience and could figure this one out. Thanks

我添加了一些javascript:

I've added some javascript:

$('#custom_order').append('<tr id="custom_'+category+'_row"><td'+padding+'>'+header+'<select id="custom_'+category+'" name="'+category+'" style="background-color:#EDEDED;border:1px solid #C0CEDB;width:280px;font-size:0.87em"></select>'+plusspan+'</td></tr>');

for (var i=0;i<components[category]['value'].length;i++){
    $('#custom_'+category).append('<option id="'+components[category]['value'][i]['id']+'" value="'+components[category]['value'][i]['price']+'"></option>');
    removals(category,i);
    dependencies(category,i);
    selectInput(category);
}
getDiff(category);

getDiff()函数使用html()函数将值添加到选项中。奇怪的是,如果我在getDiff()函数之后提示选项的html,它会显示填写的值。并且我将getDiff()函数放在生成选项的for循环中,它填充值并在IE中显示它们,而不是最后一个。

getDiff() function adds the values to the options with html() function. The weird thing is, if I alert the html of the option just after the getDiff() function, it shows the value filled out. And it I put the getDiff() function in the for loop where the options are generated, it fills the values and shows them in IE, just not the last one.

我在循环外调用getDiff()进行优化,因为我可以在生成所有选项之后添加值。好吧,至少我认为我可以,因为它适用于Firefox和Chrome。

I'm calling getDiff() outside the loop for optimization, and since I can add the values later after all the options are generated. Well at least I thought I could, since it works on Firefox and Chrome.

推荐答案

在不知道你的JavaScript的情况下很难回答这个问题。您是否可以提供一些示例代码来演示JavaScript如何进行动态生成。

Without knowing your JavaScript it's hard to answer this. Can you even give a sample bit of code that demonstrates how the JavaScript is doing the dynamic generation.

这就是说,我之前遇到过这方面的问题。通常,它是通过将'options'指定为选择的HTML而不是实现创建'SELECT'DOM元素,创建关联的'OPTIONS'DOM元素,然后以正确的方式正确地将其附加到DOM。

That said, I have encountered issues in this area before now. Generally, it has arisen from specifying the 'options' as the HTML to the select, rather than actuall creating a 'SELECT' DOM element, creating the associated 'OPTIONS' DOM elements and then correctly appending this to the DOM in the correct way.

jQuery应该为你解决这个问题,但是,如果没有至少一些代码,很难知道你的问题是什么。

jQuery ought to hangle this for you, but, again, its difficult to know what your issue is without at least some code.

这篇关于选择未在IE中显示的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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