【发布时间】:2016-11-22 02:40:17
【问题描述】:
我有以下html:
<table class="code-table hljs">
<tbody>
<tr class="code-row">
<td class="line-number unselectable">1</td>
<td class="code-col">one</td>
</tr>
<tr class="code-row">
<td class="line-number unselectable">2</td>
<td class="code-col">two</td>
</tr>
<tr class="code-row">
<td class="line-number unselectable">3</td>
<td class="code-col">three</td>
</tr>
</tbody>
</table>
相关的css:
.unselectable {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
在 Firefox 和 Chrome 中,如果我选择所有 (ctrl-a),我期望发生的情况是,只会选择“一”、“二”和“三”,而不是行号。但是,当我粘贴剪贴板中的内容时,我会得到不同的结果:
Chrome 输出:
one
2 two
3 three
火狐输出:
one
two
three
因此,Chrome 会复制除第一行之外的所有不可选择的行,而 Firefox 会在不应该存在的地方添加一个额外的行。
当前 Chrome 版本为 54.0.2840.71 m,当前 firefox 版本为 49.0.2(根据http://caniuse.com/#feat=user-select-none,两者都可以使用user-select: none;
目前是否可以使用 css 解决方案?
编辑 请注意,我收到的表正在由另一个库呈现,我真的只能操作类。
【问题讨论】:
-
请注意specification is still in Working Draft status,但声明:本规范对剪贴板的行为没有规范要求。您将看到浏览器没有剪贴板时会发生什么一个标准,告诉他们如何表现。