如何使用jQuery禁用文本选择? [英] How to disable text selection using jQuery?

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

问题描述

jQuery或jQuery-UI是否具有禁用给定文档元素的文本选择的任何功能?

Does jQuery or jQuery-UI have any functionality to disable text selection for given document elements?

推荐答案

在jQuery 1.8中,这可以按如下方式完成:

In jQuery 1.8, this can be done as follows:

(function($){
    $.fn.disableSelection = function() {
        return this
                 .attr('unselectable', 'on')
                 .css('user-select', 'none')
                 .on('selectstart', false);
    };
})(jQuery);

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

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