问题
I have function preventing selecting element, under other clicking element. Fumction works fine in chrome, but in IE11, e.detail doesn`t work. What use instead? How to reorganize function code?
function xorClick(e) {
if (pendingClick) {
clearTimeout(pendingClick);
pendingClick = 0;
}
switch (e.detail) {
case 1:
pendingClick = setTimeout(function() {
var parent = e.target.closest('.ui-treenode-content');
parent.click();
}, 180);
break;
case 2:
var parent = e.target.closest('.ui-treenode-content');
parent.firstChild.click();
break;
default:
break;
}
stopClick(e);
I tried to use
var nDelta = e.detail === 0 ? e.wheelDelta : e.delta;
But it is not working too.
function stopClick(e) {
if (e.preventDefault) {
e.preventDefault();
} else {
e.returnValue = false;
}
e.stopPropagation();
}
<span onclick="xorClick(event)">
<div onclick="stopClick(event)">
.....
</div>
</span>
回答1:
As you can read in the IE11 docs:
Note Starting with Internet Explorer 11, this event fires a MSPointerEvent object instead of MouseEvent. You can use the
MouseEvent.pointerType
property to determine the type of contact that the click originated from (touch, mouse, or pen).
From what I can see in difference between e.detail
in IE11 and Firefox/Edge is that IE11 returns 0, but the others return 1. Maybe you just have to add that case in your switch
statement?
来源:https://stackoverflow.com/questions/55903854/how-to-work-with-event-detail-in-internet-explorer-11