从复制的文本中删除文本 [英] Delete text from copied text

查看:70
本文介绍了从复制的文本中删除文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JavaScript清理从我的网站复制的文本。

I would like to use JavaScript to clean up text that’s being copied from my site.

我使用如下代码段:

body {
    vertical-align: middle; ➊
}

其中➊表示以后会发表评论。我希望读者复制此片段并使用它-因此,我需要删除该Unicode标记。我该如何访问要复制的文本并对其进行更改?

Where ➊ indicates comment later on. I want readers to copy this snippet and use it – so I need to delete that Unicode marker. How can I access text that’s being copied and make changes to it?

我考虑了在用户单击(鼠标移下)时从片段中删除标记,因此她可以选择文本,将其复制,然后恢复标记,但这似乎是很长的路要走。

I considered deleting marker(s) from snippet when user clicks (mousedown) on it, so she could select the text, copy it and then I would restore markers but it seems a really long way to do it.

推荐答案

span标记中的unicode标记,并在用户单击时不显示任何标记

Just put the unicode markers in span tags, and put display none on them when the user clicks

body {
    vertical-align: middle; <span class="marker">➊</span>
}

然后在jQuery中完成

And then do this in jQuery

$('.code')
    .mousedown(function() {
        $(this).find('.marker').css('display','none');
    })
    .mouseleave(function() {
        $(this).find('.marker').css('display','inline');
    });

作为奖励,您可以将以下样式应用于元素:

As a bonus, you could then apply the following style to the .marker elements:

​.marker
{
    position:absolute;   
    right:0;
}​

这篇关于从复制的文本中删除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆