小编典典

如何使用jQuery禁用文本选择?

javascript

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


阅读 409

收藏
2020-05-01

共1个答案

小编典典

在jQuery 1.8中,可以按照以下步骤进行操作:

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