我有以下代碼。該代碼基於完成的選擇填充列表框。但我的代碼在IE 7 &失敗對IE 6單擊問題在IE 6
//----------------------------------------------------------------------------------------------
//fill the location list on the basis of Country
function FillLocationList()
{
var opt = document.createElement("OPTION");
var selected =document.getElementById('drpCountryName').selectedIndex;
var size = document.getElementById('drpCountryName').options.length;
if(!event.ctrlKey && !event.shiftKey)
{
document.getElementById('drpLocation').options.length = 0;
for(var i=0;i<locationArray.value.length;i++)
{
//if(document.getElementById('drpLocationReportsTo').value == locationArray.value[i].LocationRptId)
if(document.getElementById('drpCountryName').value == locationArray.value[i].CountryCode)
{
opt = document.createElement("OPTION");
opt.text = locationArray.value[i].LocationName;
opt.value=locationArray.value[i].LocationId;
document.getElementById("drpLocation").options.add(opt);
}
}
}
else if(event.ctrlKey || event.shiftKey)
{
document.getElementById('drpLocation').length = 0;
for(j=0;j<document.getElementById('drpCountryName').length;j++)
{
var currentLocation = document.getElementById('drpCountryName').options[j].value;
if(document.getElementById('drpCountryName').options[j].selected)
{
for(var i=0;i<locationArray.value.length;i++)
{
if(currentLocation == locationArray.value[i].CountryCode)
{
opt = document.createElement("OPTION");
opt.text = locationArray.value[i].LocationName;
opt.value=locationArray.value[i].LocationId;
document.getElementById("drpLocation").options.add(opt);
}
}
}
}
}
}
它究竟在哪裏失敗? – 2010-01-12 12:32:49
適用於IE6的我,請完整的測試用例。但是請注意,'options.add'是一種非標準的方法,不能在IE之外工作(而不是使用'options [options.length] = opt'),並且全局'event'的使用僅限於IE並且在任何情況下可能都不宜)。 – bobince 2010-01-12 13:48:45