Prevent onClick event when selecting text

后端 未结 5 1801
星月不相逢
星月不相逢 2020-12-15 16:16

I\'ve got this problem where I need to show and hide divs when clicking on a table cell. However, I also want people to be able to select text and copy it within the cell wi

5条回答
  •  一生所求
    2020-12-15 16:39

    You can use mouseup, mousedown and mousemove events to achieve this:

    DEMO

    var isDragging = false;
    $("#clickshow")
    .mousedown(function() {
        isDragging = false;
    })
    .mousemove(function() {
        isDragging = true;
     })
    .mouseup(function() {
        var wasDragging = isDragging;
        isDragging = false;
        if (!wasDragging) {
            $("#information").toggle();
            $("#clicktoshow").toggle();
        }
    });
    

    SOURCE

提交回复
热议问题