防止清除选择
Prevent Clearance of Selection
<p>Select Some of This Text</p>
<span>Now click this</span>
是否可以做到当您单击 <span>
时它不会删除 <p>
的选择或将其存储在某处?也许使用 onblur
事件?
一种方法是使用 How to disable text selection highlighting? 中解释的 CSS 来防止在“现在单击此按钮”中选择文本。使用此 CSS,单击按钮不会更改选择,包括是否存在现有选择。
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<p>Select Some of This Text</p>
<span class="unselectable">Now click this</span>
<p>Select Some of This Text</p>
<span>Now click this</span>
是否可以做到当您单击 <span>
时它不会删除 <p>
的选择或将其存储在某处?也许使用 onblur
事件?
一种方法是使用 How to disable text selection highlighting? 中解释的 CSS 来防止在“现在单击此按钮”中选择文本。使用此 CSS,单击按钮不会更改选择,包括是否存在现有选择。
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
<p>Select Some of This Text</p>
<span class="unselectable">Now click this</span>