Skip to content

Instantly share code, notes, and snippets.

@WenLiangTseng
Created July 22, 2013 05:06
Show Gist options
  • Save WenLiangTseng/6051395 to your computer and use it in GitHub Desktop.
Save WenLiangTseng/6051395 to your computer and use it in GitHub Desktop.
讓滑鼠不能選擇文字(適用於一些 drag and drop 的功能,而非防盜copy)
//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);
//example
jQuery('.selector').disableSelection();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment