javascript - 当 contenteditable=true 时选择文本将复制样式为 user-select=none 的节点文本;

标签 javascript html css contenteditable

遇到问题了。当您打开 Fiddle 时,您将看到一个内容可编辑的页面。某些节点具有 user-select=none 样式,当您按 ctrl-a 全选时,您将看到所有内容都被选中,而没有 user-select:none 样式的内容

但是,如果您使用 ctrl-c 复制所选文本并打开记事本并粘贴它,则所有带有 user-select=none 的文本都会插入其中。

JS Fiddle

最佳答案

您的代码在 Firefox 上运行良好,但在 ChromeOperaSafari 上运行不正确>.

我认为值为 noneuser-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/

相关文章:

css - 在sass中使用迭代制作@for循环

css - Twitter Bootstrap - 如何在同一行和多个屏幕尺寸上处理多个输入的水平表单?

javascript - 在循环集合中寻找最短路径

html - 在 CSS 文件中使用相对 URL,它相对于什么位置?

javascript - 箭头函数中 Object.values() 的未知行为

php - Javascript 不会在 php 页面上运行

css - 移动设备上的固定内容,一个好的解决方法?

javascript - 使用自定义 jQuery 防止回发确认在 asp 上实现 :LinkButton

javascript - 如何使 Raphael js 打印方法在本地计算机上适用于法语、德语等字符?

javascript - 为什么这个混淆代码在 JavaScript 中是恶意的?