javascript - IE 6 中的单击问题

标签 javascript internet-explorer

我有以下代码。该代码根据完成的选择填充列表框。但我的代码在 IE 7 上运行,在 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);
                    }
                }
            }
       }

    }

}

最佳答案

该函数在 IE6 下触发吗?因为一个常见的问题是将函数附加到onclick事件上(在IE6下有问题)。

改用onchange

关于javascript - IE 6 中的单击问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2048859/

相关文章:

javascript - 为什么这个JS自调用函数不起作用?

internet-explorer - 什么是 ie 过滤器(如果有)用于 css3 倾斜

javascript - IE 中数据属性长度的限制?

windows - 如何让Internet Explorer在某个域自动登录

javascript - Handlebars js : how to get a variable in an each loop?

javascript - document.getElementById ("ID").focus() + 谷歌浏览器

javascript - innerwidth 和 innerheight 在 android 和 safari 上获得不同的值

javascript - 如何从下到上为元素的最大高度设置动画?

css - 文本动画在 IE 中不起作用

internet-explorer - Facebook Connect 登录不再适用于 IE