我想在表中创建一个不可复制的元素(因为可读性更好)。
在Firefox中它工作正常。如果选择所有内容并复制它,则不会复制特定的文本元素。
不幸的是,在Chrome中,这不起作用。实际上,浏览器并不选择文本,而是复制文本。

<td unselectable="on" id="unselectable">Test2</td>

#unselectable {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

示例:http://jsfiddle.net/pXAeB/
这个问题有解决办法吗?

最佳答案

Demo Fiddle
将以下内容添加到表元素中:

unselectable='on'
onselectstart='return false;'
onmousedown='return false;'

你的表元素。注意,对于Chrome,大多数时候只要包含onselectstart='return false;'就足够了。

关于html - 尽管使用“-webkit-user-select:无”,Chrome仍会复制文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22321081/

10-09 15:18
查看更多