构建了一个功能,可以取消选择除 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;
}
}
}
源代码 - 相关代码:
.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/