double click using IE

后端 未结 2 705
走了就别回头了
走了就别回头了 2020-12-21 08:30

I have discovered a double-click problem in IE.

The following is my HTML:

Hello World!

And my jQ

相关标签:
2条回答
  • 2020-12-21 08:57

    Here's a fiddle. jQuery's dblclick works for me on both FF and IE9. Tested: "the event is fired only when the double click STARTS and ENDS inside the DIV"

    $("#test").dblclick(function(event) {
      event.stopPropagation();
      $(this).css({'background-color': 'red'});
    });
    
    0 讨论(0)
  • 2020-12-21 09:00

    (on)dblclick event is a native javascript event, not a jquery's event

    Dblclick event is not consistent across browsers, see this ticket 3 years old but still valid in some way: http://bugs.jquery.com/ticket/7876 even now sequence in IE10 is the same as FF/Chrome/Safari but as you noted it, there are still some bugs.

    As a workaround, you could use this snippet instead of dblclick event:

    DEMO with custom dblclick

    $('#test').on('click', function(event){
        var t = this;
        if (!t.clicks) t.clicks = 0;
             ++t.clicks;
             if (t.clicks === 2) {
                 t.clicks = 0;
                 //here the kind of dclclick is fired ...
                 $(t).css({'background-color' : "red"});
             }
             setTimeout(function () {
                 t.clicks = 0
             }, 500);//duration value can be change depending of your wishes
    
    });
    

    An other workaround could be to bind/unbind dblclick event on mousedown/mouseenter/mouseleave (hover) handlers, like that:

    DEMO with mousedown/mouseenter/mouseleave

    $('#test').hover(function () {
        $(this).on('mousedown.cust', function () {
            $(this).on('dblclick.cust', function () {
                $(this).css({
                    'background-color': "red"
                });
            });
        });
    }, function () {
        $(this).off('mousedown.cust dblclick.cust');
    });
    
    0 讨论(0)
提交回复
热议问题