【问题标题】:Why does VEMap onclick event work in other browsers but not Firefox?为什么 VEMap onclick 事件在其他浏览器中有效,而在 Firefox 中无效?
【发布时间】:2010-12-06 17:44:19
【问题描述】:

我有一个带有以下相关代码的 VEMap 控件:

map = new VEMap('map');

map.AttachEvent("onclick", DoContinents);

function DoContinents(event)
     {
        if (event.elementID != null)
        {
        //var shape = map.GetShapeByID(event.elementID);
        //var id = shape.GetID();
        //var id = event.elementID;
        //alert (event.elementID);
        if (event.elementID == 'msftve_1001_200000_10000')
            {
                map.SetCenterAndZoom(new VELatLong(15, -90), 2);
        }
          else if (event.elementID == 'msftve_1001_200001_10001')
            {
                map.SetCenterAndZoom(new VELatLong(48, 23), 2);
            }
             else if (event.elementID == 'msftve_1001_200002_10002')
            {
            map.SetCenterAndZoom(new VELatLong(4, 18), 2);
                }
             else if (event.elementID == 'msftve_1001_200003_10003')
            {
                map.SetCenterAndZoom(new VELatLong(43, 87), 2);
                }
            else if (event.elementID == 'msftve_1001_200004_10004')
            {
                map.SetCenterAndZoom(new VELatLong(-25, 134), 2);
                }

            cont.Hide();
            vid.Show();
            $('#sidebar_list').show();
            $('#legend').show();
        }
     }

它在 Chrome 中运行良好,甚至在 IE 中也运行良好!但是,当我在 Firefox 中加载页面时,单击地图图标时什么也没有发生。经过进一步调查,我发现该事件在所有浏览器中都会触发并且DoContinents 运行。在 Chrome 和 IE 中,event.elementID 包含我单击的 VEShape 的 ID,但在 Firefox 中,event.elementID 为空(即使存在事件对象)!显然这会导致我的DoContinents 事件处理程序中的代码无法运行。为什么在 Firefox 中会发生这种情况,而在我的其他浏览器中却没有?

【问题讨论】:

    标签: javascript dom-events virtual-earth


    【解决方案1】:

    这很难追踪,但事实证明,如果满足以下条件,VEMap 事件就会中断。它们仍然会触发,但缺少关键事件数据,例如 elementID。

    1. 仅在 Firefox 中发生
    2. mootools JS 框架正在加载时(不一定正在使用)

    当满足这些条件时,就会出现上述问题。

    请注意,Joomla 会自动加载 mootools。这就是发生在我身上的事。

    【讨论】:

      猜你喜欢
      • 2019-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-20
      • 1970-01-01
      • 1970-01-01
      • 2015-10-21
      • 1970-01-01
      相关资源
      最近更新 更多