在 jQueryUI 中禁用选择是用来做什么的?

有没有人能帮我理解一下为什么这个有用以及什么时候使用它?

$( "#sortable" ).disableSelection();
36101 次浏览

It's useful if you want to make text unselectable. If, for instance, you want to make drag-and-drop elements with text on, it'd be annoying to the user if the text on the box accidentally would get selected when trying to drag the box.

Caveat emptor: .disableSelection() is actually harmful on some browsers, as it prevents clicking active elements (e.g. textareas) inside the sortable.

  • Firefox 33.1 for Mac OS X (Yosemite): .disableSelection() prevents clicking on embedded textarea; doesn't seem to have any effect otherwise (i.e. it is still impossible to select text with the mouse in the sortable if omitted)
  • Chrome 39.0.2171.71 (64-bit) for Mac OS X: .disableSelection() seems to have no effect whatsoever.

jQuery documentation says to not use it http://api.jqueryui.com/disableselection/

Also, I found that it made elements with contenteditable="true" no longer editable.