简体   繁体   English

如何在Internet Explorer 10+中检测点击次数

[英]How do I detect the number of clicks in Internet Explorer 10+

I need to know how to detect the number of clicks on an HTML element. 我需要知道如何检测HTML元素上的点击次数。 With Firefox and Chrome, I use the "event" object and check its "detail" property. 对于Firefox和Chrome,我使用“事件”对象并检查其“详细信息”属性。 With a "mousedown" handler, I only want to initiate a "drag" on an element (move it around the screen using CSS) on the FIRST click: 使用“ mousedown”处理程序,我只想在第一次单击时在元素上启动“拖动”(使用CSS在屏幕上将其移动):

if (event.detail>1) return; 如果(event.detail> 1)返回;

But Internet Exploder 11 (I assume the same for 10+) the event.detail===5 on the first click. 但是Internet Exploder 11(我对10+假定相同)在第一次单击时为event.detail === 5。 IE9 returns the "proper" value of 1. IE9返回“正确”值1。

The only thing I can think of is to use "setInterval()" to periodically (every .5 seconds or so) set a "global" value to =0, then increment that value on each "mousedown" and use that count instead of the "event.detail". 我唯一想到的是使用“ setInterval()”定期(每0.5秒左右)将“全局”值设置为= 0,然后在每个“鼠标按下”时递增该值,并使用该计数代替“ event.detail”。

Ridiculous, methinks. 荒唐可笑。

You can see this problem (until I fix it) at: 您可以在以下位置看到此问题(直到我修复):

http://softmoon-webware.com/MasterColorPicker_instructions.php http://softmoon-webware.com/MasterColorPicker_instructions.php

The actual javascript code in question is in the file (the the very end): 有问题的实际javascript代码在文件中(末尾):

http://softmoon-webware.com/color-pickers/SoftMoon-WebWare/MasterColorPicker2.js http://softmoon-webware.com/color-pickers/SoftMoon-WebWare/MasterColorPicker2.js

After clicking on the input box on the left (that says try here), you should be able to "drag" the "picker panels" by their handles around the screen. 单击左侧的输入框(即在此处尝试)后,您应该能够通过屏幕周围的手柄“拖动”“选择器面板”。 No problem using a real browser, and even though IE9 is about maxxed out with the codebase (yes, it throws stack-overflow errors!) it will (or did before the last update that worked with the "FD-sliders" was implemented that started the stack overflow problems) allow dragging the panels. 使用真正的浏览器没问题,即使IE9的代码库已达到极限(是的,它也会引发堆栈溢出错误!),它将(或者在实现与“ FD滑块”一起使用的最后一次更新之前完成)引发了堆栈溢出问题),允许拖动面板。 IE10+ only "highlights" (selects) the text under the curser, won't drag, again because of the "wrong" "event.detail" value. IE10 +仅“突出显示”(选择)光标下方的文本,不会拖动,这同样是因为“错误”的“ event.detail”值。 To be fair, nothing I can find on the Microsoft Developer Network pages says what the event.detail specs actually are (just "gives further info about the event..."), and the link to W3C pages don't seem to have specs for the "event.detail" property either. 公平地说,我在Microsoft开发人员网络页面上找不到任何内容说明event.detail规范实际上是什么(只是“提供有关该事件的更多信息...”),并且到W3C页面的链接似乎没有“ event.detail”属性的规范。

Am I missing something here? 我在这里想念什么吗?

code extract from file: 从文件中提取代码:

for (var i=0, handle, panels=MasterColorPicker.panels;  i<panels.length;  i++)  {
    if (panels[i]===MasterColorPicker.mainPanel)  continue;
    if (panels[i].id==='MasterColorPicker_options')  {
        handle=panels[i].getElementsByTagName('header')[0];             // ↓ ↓ for drag, the first panel must be the largest and contain the other(s) in its margin
        UniDOM.addEventHandler(handle, 'onmousedown', dragPanel, false, [MasterColorPicker.mainPanel, panels[i]]);
        UniDOM.addEventHandler(handle, 'onmouseup', returnPanelsOn3, false, [MasterColorPicker.mainPanel, panels[i]]);  }
    else  {
        handle=panels[i].getElementsByTagName('h2')[0].getElementsByTagName('span')[0];
        UniDOM.addEventHandler(handle, 'onmousedown', dragPanel, false, [panels[i]]);
        UniDOM.addEventHandler(handle, 'onmouseup', returnPanelsOn3, false, [panels[i]]);  }
    UniDOM.addEventHandler(handle, 'oncontextmenu', abortContextMenu);  }
UniDOM.addEventHandler(document.getElementById("MasterColorPicker_returnPanelsOn3"), 'onmouseup', returnPanelsOn3, false, panels);
function dragPanel(event, stickyPanels)  { console.log("IE sucks: detail: "+event.detail);
    event.stopPropagation();
    event.preventDefault();
    if (event.detail>1  ||  !MasterColorPicker.enablePanelDrag)  return;
    var stick=(event.shiftKey || event.button===2) && MasterColorPicker.enableStickyPanels && (UniDOM.MS_exploder!==9),
            ttcn= (stick ? 'MCP_thumbtack' : ""),
            CSS=getComputedStyle(stickyPanels[0], null),
            mOff= (CSS.position==='fixed') ?
                    {x: (document.body.offsetWidth-event.clientX)-parseInt(CSS.right),  y: event.clientY-parseInt(CSS.top)}
                : UniDOM.getMouseOffset(stickyPanels[0], event),
        dragHandle=event.currentTarget,
            move=UniDOM.addEventHandler(document.body, 'onmousemove', function(event)  {
                var CSS=getComputedStyle(stickyPanels[0], null);
                if (CSS.position==='fixed')
                var b={w: document.body.offsetWidth, h: document.documentElement.clientHeight || window.innerHeight, x: 0, y: 0},
                        y=(event.clientY - mOff.y),
                        x=((b.w-event.clientX) - mOff.x);
                else
                var b=UniDOM.getElementOffset(stickyPanels[0].offsetParent, MasterColorPicker.dragBounder),
                    b={y: b.y, x: b.x, w: MasterColorPicker.dragBounder.offsetWidth, h: MasterColorPicker.dragBounder.offsetHeight},
                    m=UniDOM.getMouseOffset(stickyPanels[0].offsetParent, event),
                        y=m.y - (parseInt(CSS.marginTop) + mOff.y),
                        x=(b.w-m.x) - (stickyPanels[0].offsetWidth-mOff.x) + parseInt(CSS.marginRight);
                y= (y<-b.y) ?  (-b.y)  :  ( (y>(m=b.h-(stickyPanels[0].offsetHeight+parseInt(CSS.marginTop)+parseInt(CSS.marginBottom)+b.y))) ? m : y );
                x= (x<-b.x) ?  (-b.x)  :  ( (x>(m=b.w-(stickyPanels[0].offsetWidth+parseInt(CSS.marginLeft)+parseInt(CSS.marginRight)+b.x))) ? m : x );
                for (i=0;  i<stickyPanels.length;  i++)  {
                    stickyPanels[i].style.top= y + 'px';
                    stickyPanels[i].style.right= x + 'px';  }
                event.stopPropagation();
                event.preventDefault();  }
            , true),
            blockMenu=UniDOM.addEventHandler(document.body, 'oncontextmenu', abortContextMenu, true),
            drop=UniDOM.addEventHandler(document.body, 'onmouseup', function(event)  {
                move.onmousemove.remove();  blockMenu.oncontextmenu.remove();  drop.onmouseup.remove();
                event.stopPropagation();
                event.preventDefault();
              for (var i=0;  i<stickyPanels.length;  i++)  {UniDOM.removeClass(stickyPanels[i], ['dragging', ttcn]);}
                UniDOM.removeClass(document.body, ['MCP_drag', ttcn]);
                if (stick) dragHandle.removeChild(MasterColorPicker.thumbtackImage);
                try {MasterColorPicker.dataTarget.focus();} catch(e) {}  }
            , true);
  for (var i=0;  i<stickyPanels.length;  i++)  {
      UniDOM.addClass(stickyPanels[i], ['dragging', ttcn]);
        MasterColorPicker.setTopPanel(stickyPanels[i]);  }
    if (stick)  {
        mOff.x=stickyPanels[0].offsetWidth-mOff.x;
        if (CSS.position==='fixed')  {
            mOff.y= -(parseInt(CSS.marginTop)-mOff.y);
            var currentCN='floating', newCN='scrollable';  }
        else  {
            mOff.y += parseInt(CSS.marginTop);
            var currentCN='scrollable', newCN='floating';  }
      while (--i>=0)  {UniDOM.swapOutClass(stickyPanels[i], currentCN, newCN);}
      dragHandle.appendChild(MasterColorPicker.thumbtackImage);
      move.onmousemove.wrapper(event);  }
    UniDOM.addClass(document.body, ['MCP_drag', ttcn]);  }
function returnPanelsOn3(event, stickyPanels)  {
    event.stopPropagation();
    event.preventDefault();
    if (event.detail!==3  ||  event.button!==0)  return;
    MasterColorPicker.returnPanelsHome(stickyPanels);  }
function abortContextMenu(event) {event.preventDefault();  event.stopPropagation();}
MasterColorPicker.returnPanelsHome=function(stickyPanels)  {
  for (var i=0;  i<stickyPanels.length;  i++)  {
        stickyPanels[i].style.top= "";
        stickyPanels[i].style.right= "";
        UniDOM.removeClass(stickyPanels[i], ['scrollable', 'floating']);  }  }

Just keep a count of how many times your mousedown handler has been called: 只需记录一下您的mousedown处理程序被调用的次数即可:

var clickCount = 0;
$('#myElement').on('mousedown', function(){
    clickCount++;
    if (clickCount > 1)
        return;
    [ ... ]
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何为脚本标签检测Internet Explorer 10? - How to detect Internet Explorer 10 for script tags? Javascript / Jquery在Internet Explorer 10+中导出到Excel - Javascript/Jquery export to Excel in Internet Explorer 10+ 如何检测IE 10+的onerror事件 - How to detect IE 10+ for an onerror event 如何通过 Javascript 检测 Internet Explorer 的临时 Internet 文件位置? - How do I detect the temporary Internet Files location of Internet Explorer through Javascript? 在某些情况下,例如特定于Internet Explorer的CSS或特定于Internet Explorer的JavaScript代码,如何仅将Internet Explorer 10定位? - How do I target only Internet Explorer 10 for certain situations like Internet Explorer-specific CSS or Internet Explorer-specific JavaScript code? 如何在IE9中检测浏览器模式是否在“Internet Explorer 9兼容性视图”中? - How do I detect if the Browser mode is in “Internet Explorer 9 compatibility View” in IE9? 如何将 Internet Explorer 10 支持添加到简单的 VueJs 组件? - How do I add Internet Explorer 10 support to a simple VueJs component? 如何检测GNOME AppMenu上的点击? - How do I detect clicks on the GNOME AppMenu? 如何在Internet Explorer 8中获取innerWidth - How Do I Get innerWidth in Internet explorer 8 检测Internet Explorer(也可以使用IE10 +!) - detect Internet Explorer (working with IE10+ too!)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM