How to work with event.detail in Internet Explorer 11?

∥☆過路亽.° 提交于 2020-01-24 22:14:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!