遇到问题了。当您打开 Fiddle 时,您将看到一个内容可编辑的页面。某些节点具有 user-select=none 样式,当您按 ctrl-a 全选时,您将看到所有内容都被选中,而没有 user-select:none 样式的内容
但是,如果您使用 ctrl-c 复制所选文本并打开记事本并粘贴它,则所有带有 user-select=none 的文本都会插入其中。
最佳答案
您的代码在 Firefox 上运行良好,但在 Chrome、Opera、Safari 上运行不正确>.
我认为值为 none 的 user-select 属性在某些浏览器中存在一些错误。
在不同的浏览器中尝试此示例代码,您就会知道。
.noselect {
-webkit-touch-callout: none; /* iOS Safari */
-webkit-user-select: none; /* Safari */
-khtml-user-select: none; /* Konqueror HTML */
-moz-user-select: none; /* Firefox */
-ms-user-select: none; /* Internet Explorer/Edge */
user-select: none; /* Non-prefixed version, currently
supported by Chrome and Opera */
}
<p>Selectable text1.</p>
<p class="noselect">Unselectable text1.</p>
<p>Selectable text2.</p>
<p class="noselect">Unselectable text2.</p>
关于javascript - 当 contenteditable=true 时选择文本将复制样式为 user-select=none 的节点文本;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47845589/