如何通过光标拖动阻止文本/元素选择 [英] How can I prevent text/element selection with cursor drag

查看:182
本文介绍了如何通过光标拖动阻止文本/元素选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个分页控件,我注意到点击按钮时很容易意外地选择单个图像和文本。是否有可能阻止这种情况?

I made a paging control and I noticed that while clicking on the buttons it is very easy to accidentally select the individual images and text. Is it possible to prevent this?

澄清选择我的意思是用鼠标突出显示。 (尝试将鼠标从屏幕的一侧拖到另一侧。)

To clarify selecting I mean highlighting with the mouse. (Try dragging your mouse from one side of the screen to the other.)

如果您尝试突出显示此网格中的文本/控件,则无法选择它。怎么做的?
链接

If you try to highlight the text/controls in this grid it can't be selected. How is that done? Link

推荐答案

拖动并选择鼠标按下事件初始化并在随后的鼠标移动时更新。当您处理事件以开始拖动或跟随鼠标时,取消事件的冒泡并覆盖默认的浏览器返回:

dragging and selecting both initialize on a mouse down event and update on subsequent mouse moves. When you handle the events to begin dragging, or to follow the mouse, cancel the event's bubbling and override the default browser return:

在您的开始拖动mousedown和移动处理程序 -

something like this in your begin dragging mousedown and move handlers-


e=e || window.event;
pauseEvent(e);




function pauseEvent(e){
    if(e.stopPropagation) e.stopPropagation();
    if(e.preventDefault) e.preventDefault();
    e.cancelBubble=true;
    e.returnValue=false;
    return false;
}

这篇关于如何通过光标拖动阻止文本/元素选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆