event.ctrlKey适用于IE和Chrome,但不适用于legendItemClick [英] event.ctrlKey works in IE and Chrome but not Firefox on legendItemClick
问题描述
在 http://试试jsfiddle jsfiddle.net/PJVK3/
试图用简单的javascript代码捕获相同的事件,并发生相同的问题。
这可以在Chrome(24.0.1312.57)和IE(9)中使用,但不能在Firefox(18.0.2)中使用:
pre $ <!DOCTYPE html>
< html>
< head>
< script>
函数myFunction()
{
if(event.ctrlKey){document.getElementById(demo)。innerHTML =ctl key pressed;}
if(!event innerHTML =ctl key NOT pressed;}
}
< / script>
< / head>
< body>
< p>点击按钮触发功能。< / p>
< button onclick =myFunction()>点击< /按钮>
< p id =demo>< / p>
< / body>
< / html>
Whatup?如果你看看源代码,你会发现它将事件存储在 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? 可见:隐藏;
if(!e.browserEvent.ctrlKey){
if(!confirm('该系列当前为'+
visibility +',你想改变它吗? )){
return false;
$ b $ / code $ / pre>
源代码:
.on('click',function(event) {
var strLegendItemClick ='legendItemClick',
fnLegendItemClick = function(){
item.setVisible();
};
//传递点击/触摸事件#4。
event = {
browserEvent:event //< - 这里是神奇的
};
//点击(item.firePointEvent){//点
item.firePointEvent(strLegendItemClick,event,fnLegendItemClick);
} else {
fireEvent(item,strLegendItemClick,事件,fnLegendItemClick);
}
});
Built a feature that deselects all but the ctrl-clicked item. It works fine in IE and Chrome, but not in Firefox.
Try the jsfiddle at http://jsfiddle.net/PJVK3/
Tried to capture the same event with simple javascript code and the same problem occurs.
This works in Chrome(24.0.1312.57) and IE(9), but not 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>
Whatup? anyone?
解决方案 If you take a look the source code you'll see that it stores the event on event.browserEvent
.
It's a fixed bug: https://github.com/highslide-software/highcharts.com/pull/992
So, why you have to use event.browserEvent
instead of window.event
?
Simple, because window.event
doesn't exist in 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;
}
}
}
Source code - relevant code:
.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);
}
});
这篇关于event.ctrlKey适用于IE和Chrome,但不适用于legendItemClick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!