html下select追加元素,IE下错误

var selectCtr=window.document.getElementById("lesson_up");

selectCtr.add(opt,selectCtr.options[selectCtr.length-1]); 短短2行代码。很简单。里边的事情还是比较多的。以前习惯写

window.document.from1.lesson_up.options[window.document.from1.lesson_up.length] = new Option(subcat[i][0], subcat[i][2], opt)

这中,在chrome下,没问题。就以为没问题。今天,同事报告发现错误了,我就换着怀疑的心情去看了。发现chrome没问题。高版本IE下确实有问题。

就换个一种写法,selectCtr.add(Optitem),测试了一下,发现好了一部分。在IE11下还是有问题,就继续找找资料。最后发现了一种新的写法,selectCtr.add(opt,null).

这种 ,FF下有问题。就继续寻找,终于找到了一种,方法,把集中情况给兼容下来。

原文地址:https://www.cnblogs.com/wcLT/p/3620828.html