阻止在 Safari 和 Firefox 中选择和复制表格列?

发布于 2024-07-28 00:06:53 字数 282 浏览 15 评论 0原文

我正在开发一个基本上是一个小实用程序,它在一个有两列的表中显示一段源代码,一列用于行号,一列用于实际源代码。

我发现您可以使用以下 CSS 来阻止选择文本的外观:

table th {
    -moz-user-select: none;
    -webkit-user-select: none;
}

不幸的是,这不起作用。 虽然文本似乎被选中,但如果您复制并粘贴,仍然会复制它。

那么实际上有办法做到这一点吗?

I'm working on what is basically a small utility that displays a piece of sourcecode in a table which has two columns, one for line numbers and one for the actual source.

I found that you can prevent the appearance of text being selected with the following CSS:

table th {
    -moz-user-select: none;
    -webkit-user-select: none;
}

Unfortunately this doesn't work. While the text appears not to be selected, if you copy and paste is will still copy it.

So is there actually a way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

戈亓 2024-08-04 00:06:53

选择什么取决于 DOM 树中的顺序。 因此,您需要将源显示放在显示行号的 html 之前或之后。 将源代码和行号放在单独的 div 中并使元素浮动可能是实现此目的的最简单方法。

What is selected depends on order in the DOM tree. Therefore, you need to place your source display before or after the html that displays line numbers. Putting the source and line numbers in separate divs and floating your elements is probably the easiest way to accomplish this.

貪欢 2024-08-04 00:06:53

您的问题的解决方案可以在这里找到:

行编号和复制/粘贴(HTML /CSS)

A solution to your problem can be found here:

Line numbering and copy/paste (HTML/CSS)

栀子花开つ 2024-08-04 00:06:53

您是否尝试过将它们放在单独的 div 中并使其浮动?

我还刚刚发现 this,使用 jQuery 为你做这件事。 你可以使用它,或者你可以将它拆开并弄清楚它如何显示它,然后使用它。

Have you tried putting them in a separate div and floating it?

I also just found this, uses jQuery to do it for you. You could use it, or you could take it apart and figure out how it displays it, and then use that.

究竟谁懂我的在乎 2024-08-04 00:06:53

您的所有行号都应位于单个 tr 中的单个 td 内。 如果为每一行创建一个 tr,您将无法阻止行号的复制。

请参阅此页面的来源:http://pastie.org/561138 作为示例。

All of your line numbers should reside within a single td in a single tr. If you create one tr for every line, you will be unable to prevent the copying of the line numbers.

See the source of this page: http://pastie.org/561138 for an example.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文