<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>
关于javascript - 防止清除选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48834838/