javascript - event.ctrlKey 适用于 IE 和 Chrome,但不适用于 legendItemClick 上的 Firefox

标签 javascript firefox highcharts

构建了一个功能,可以取消选择除 ctrl 键单击的项目以外的所有项目。它在 IE 和 Chrome 中运行良好,但在 Firefox 中运行不佳。
http://jsfiddle.net/PJVK3/ 尝试 jsfiddle

尝试使用简单的 javascript 代码捕获相同的事件,但出现了相同的问题。 这适用于 Chrome(24.0.1312.57) 和 IE(9),但不适用于 Firefox(18.0.2):

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
if (event.ctrlKey){document.getElementById("demo").innerHTML="ctl key pressed";}
if (!event.ctrlKey){document.getElementById("demo").innerHTML="ctl key NOT pressed";}
}
</script>
</head>
<body>
<p>Click the button to trigger a function.</p>
<button onclick="myFunction()">Click me</button>
<p id="demo"></p>
</body>
</html>

怎么了?有人吗?

最佳答案

如果查看源代码,您会发现它将事件存储在 event.browserEvent 上。
这是一个固定的错误:https://github.com/highslide-software/highcharts.com/pull/992

那么,为什么你必须使用 event.browserEvent 而不是 window.event
很简单,因为 window.event 在 Firefox 中不存在。

legendItemClick: function(e) {
    var visibility = this.visible ? 'visible' : 'hidden';

    if (!e.browserEvent.ctrlKey) {
        if (!confirm('The series is currently '+ 
            visibility +'. Do you want to change that?')) {
            return false;
        }
    }
}

demo

源代码 - 相关代码:

.on('click', function (event) {
    var strLegendItemClick = 'legendItemClick',
        fnLegendItemClick = function () {
            item.setVisible();
        };

    // Pass over the click/touch event. #4.
    event = {
        browserEvent: event                  // < -- here is the magic
    };

    // click the name or symbol
    if (item.firePointEvent) { // point
        item.firePointEvent(strLegendItemClick, event, fnLegendItemClick);
    } else {
        fireEvent(item, strLegendItemClick, event, fnLegendItemClick);
    }
});

关于javascript - event.ctrlKey 适用于 IE 和 Chrome,但不适用于 legendItemClick 上的 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14888778/

相关文章:

html - 在除 Firefox 之外的所有浏览器中都出现跳动滚动

javascript - 模板内的按钮从不调用处理程序

javascript - 时间线json.html :1 Uncaught SyntaxError: Unexpected token @ in JSON at position 1296

Javascript 不适用于 firefox 和 IE,但适用于 chrome

javascript - 为 Firefox 扩展实现 Javascript 插件系统

charts - solidgauge Highcharts 图表中正确的 borderWidth 应该是多少?

javascript - Highcharts 类型 : X-Range no space between two data sets

javascript - Xaxis 数据按降序提供给 highcharts 但 xaxis 仍然按升序出现

javascript - 基于 jQuery 的嵌入式 javascript

javascript - 填充底部在生成的文档中不起作用