该JavaScript可在Chrome和Firefox中正常运行。但是客户端使用的是IE11,在该浏览器中,只有第一个optgroup被添加到select中:
case "MPNA – MP Advisory North American Dividend":
document.getElementById("Mandate 2").style.display = "";
document.getElementById("Objective").style.display = "";
var og1 = document.createElement("optgroup");
og1.setAttribute("label", "Single Manager Fixed Income Mandates:");
select2.add(og1);
select2.options[select2.options.length] = new Option('5LBP – 5 Year CDN Laddered Bond', '5LBP – 5 Year CDN Laddered Bond');
select2.options[select2.options.length] = new Option('FBCI – Franklin Bissett (Canadian Fixed Income)', 'FBCI – Franklin Bissett (Canadian Fixed Income)');
select2.options[select2.options.length] = new Option('FTUI – Franklin Templeton (US Fixed Income)', 'FTUI – Franklin Templeton (US Fixed Income)');
select2.options[select2.options.length] = new Option('GCFI – Guardian Capital (Canadian Fixed Income)', 'GCFI – Guardian Capital (Canadian Fixed Income)');
select2.options[select2.options.length] = new Option('USLB – 5 Year US Laddered Bond', 'USLB – 5 Year US Laddered Bond');
var og2 = document.createElement("optgroup");
og2.setAttribute("label", "Risk Control Optimized Portfolio:");
select2.add(og2);
select2.options[select2.options.length] = new Option('RC10 – Risk Control - Stability (Pools)', 'RC10 – Risk Control - Stability (Pools)');
select2.options[select2.options.length] = new Option('RC11 – Risk Control - Stability (SEG &% Pools)', 'RC11 – Risk Control - Stability (SEG & Pools)');
break;
在Chrome中,正确的外观是:
在IE中,仅添加第一个optgroup:
有人有解释或解决方法吗?谢谢!
最佳答案
这些选项需要放入optgroup中。这是一个分组元素,而不是除法元素。
const select2 = document.createElement("select");
document.body.appendChild(select2);
const og1 = document.createElement("optgroup");
og1.setAttribute("label", "Single Manager Fixed Income Mandates:");
select2.appendChild(og1);
og1.appendChild(new Option('5LBP – 5 Year CDN Laddered Bond', '5LBP – 5 Year CDN Laddered Bond'));
og1.appendChild(new Option('FBCI – Franklin Bissett (Canadian Fixed Income)', 'FBCI – Franklin Bissett (Canadian Fixed Income)'));
og1.appendChild(new Option('FTUI – Franklin Templeton (US Fixed Income)', 'FTUI – Franklin Templeton (US Fixed Income)'));
og1.appendChild(new Option('GCFI – Guardian Capital (Canadian Fixed Income)', 'GCFI – Guardian Capital (Canadian Fixed Income)'));
og1.appendChild(new Option('USLB – 5 Year US Laddered Bond', 'USLB – 5 Year US Laddered Bond'));
const og2 = document.createElement("optgroup");
og2.setAttribute("label", "Risk Control Optimized Portfolio:");
select2.appendChild(og2);
og2.appendChild(new Option('RC10 – Risk Control - Stability (Pools)', 'RC10 – Risk Control - Stability (Pools)'));
og2.appendChild(new Option('RC11 – Risk Control - Stability (SEG &% Pools)', 'RC11 – Risk Control - Stability (SEG & Pools)'));
关于javascript - IE11-无法添加第二个optgroup进行选择,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/59830470/