选择框:将IE项添加到OptGroup而不是根。 FF好的 [英] SELECT box: On IE item is added to OptGroup instead of root. FF ok
问题描述
我有一个奇怪的行为选择
框和 OptGroup
:
我使用 OptGroup
,并尝试在末尾添加一个我希望退出 OptGroup
的单个项目。 FF按预期方式执行,但IE将其添加到 OptGroup
使用此代码:,所以它应该在FF中工作:
$ ($($)$($)$($)$($)$($)$($) createElement('option');
option.value = option.text =test;
select.appendChild(option);
});
I've got a behaviour a bit strange with Select
Box and OptGroup
:
I use OptGroup
and try to add at the end a single item which I expect to be out of the OptGroup
. FF does it as expected but IE adds it to the OptGroup
With this code : fiddle (Note: JQuery was just use for the .ready
method, I can't use it in my project)
<select id="selectbox">
<optgroup label="optGroup1">
<option>aaaa</option>
</optgroup>
</select>
$(document).ready(function() {
var select = document.getElementById("selectbox");
option = document.createElement( 'option' );
option.value = option.text = "test";
select.add( option );
});
The result is different in IE and FF
IE: FF:
Note : I'm using Javascript to add the item because I'm currently using GWT. So this is the way GWT adds an item to a select
.
This works in IE and Chrome, so it should work in FF:
$(document).ready(function() {
var select = document.getElementById("selectbox");
option = document.createElement( 'option' );
option.value = option.text = "test";
select.appendChild( option );
});
这篇关于选择框:将IE项添加到OptGroup而不是根。 FF好的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!