我做了一些研究自己使用的所有排列,创造一种选择对象的组合,我希望这是最好的方式,使我们可以添加选项,选择在浏览器中立的方式:
function populateSelectField()
{
document.frmMain.fldSelect.options.length = 0;
document.frmMain.fldSelect.options[document.frmMain.fldSelect.options.length]=new Option("Your Value 1");
document.frmMain.fldSelect.options[document.frmMain.fldSelect.options.length]=new Option("Your Value 2");
document.frmMain.fldSelect.options[document.frmMain.fldSelect.options.length]=new Option("Your Value 3");
document.frmMain.fldSelect.options[document.frmMain.fldSelect.options.length]=new Option("Your Value 4");
}
由于选择字段对象通过访问它的父对象(在此代码中为“frmMain”(表单))进行访问和操作,因此它不会为任何浏览器运行代码造成任何问题。
这受所有浏览器(包括IE)支持。
但我需要IE 4解决方案。 – keparo 2008-11-15 06:50:24
错误...你是否超出了某些你需要的IE4?因为这是一个非常古老的版本 - 它适用于Windows 95. – 2008-11-15 07:13:32
IE4因为不支持'document.getElementById()'而失败 - 您将不得不使用document.all。 '新的Option()'方法本身可以很好地追溯到Netscape 2.0! – bobince 2008-11-15 11:27:12