如何停止选择文本? [英] How can I stop text from being selected?

查看:104
本文介绍了如何停止选择文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的网络应用程序中,用户有时可以点击相同的按钮多次,跳过消息和事情,导致选择< / a>

In my web app the user can sometimes click the same button a number of times, skipping through messages and things, causing the </a> to be selected.

那么如何使用Javascript(jQuery)来防止这种情况呢?

So how can I prevent this using Javascript (jQuery)

推荐答案

此解决方案适用于我:
http://chris-barr.com/entry/ disable_text_selection_with_jquery /

This solution worked for me: http://chris-barr.com/entry/disable_text_selection_with_jquery/

$(function(){
    $.extend($.fn.disableTextSelect = function() {
        return this.each(function(){
            if($.browser.mozilla){//Firefox
                $(this).css('MozUserSelect','none');
            }else if($.browser.msie){//IE
                $(this).bind('selectstart',function(){return false;});
            }else{//Opera, etc.
                $(this).mousedown(function(){return false;});
            }
        });
    });
    $('.noSelect').disableTextSelect();//No text selection on elements with a class of 'noSelect'
});

这篇关于如何停止选择文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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