如何使用 jQuery 禁用文本选择? [英] How to disable text selection using jQuery?
本文介绍了如何使用 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屋!
查看全文