Web アプリの span でイベントを処理していますdblclick
。ダブルクリックの副作用として、ページ上のテキストが選択されます。この選択が行われないようにするにはどうすればよいですか?
ベストアンサー1
function clearSelection() {
if(document.selection && document.selection.empty) {
document.selection.empty();
} else if(window.getSelection) {
var sel = window.getSelection();
sel.removeAllRanges();
}
}
これらのスタイルを、IE 以外のすべてのブラウザーと IE10 の span に適用することもできます。
span.no_selection {
user-select: none; /* standard syntax */
-webkit-user-select: none; /* webkit (safari, chrome) browsers */
-moz-user-select: none; /* mozilla browsers */
-khtml-user-select: none; /* webkit (konqueror) browsers */
-ms-user-select: none; /* IE10+ */
}