“display:none”内容复制到剪贴板,粘贴时可见 [英] "display:none" content copied to clipboard, visible when pasted

查看:608
本文介绍了“display:none”内容复制到剪贴板,粘贴时可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在将未显示的HTML元素复制到剪贴板时遇到问题,然后将内容粘贴到MS Word,Outlook等时显示。

I'm having a problem with non-displayed HTML elements being copied to the clipboard, and then displayed when the content is pasted into MS Word, Outlook, etc.

例如:

<p>Hello</p>
<p style="display: none;">I'm Hidden</p>
<p>World</p>

如果我在浏览器中查看HTML,请将文本复制到剪贴板,中间段保持隐藏。好消息。

If I view that HTML in a browser, copy the text to my clipboard, then paste into Outlook, the middle paragraph remains hidden. Good news.

但是,在此示例中:

<p>Hello</p>
<input type="text" value="I'm not hidden" style="display: none;" />
<p>World</p>

如果我这样做 - 复制到剪贴板,粘贴到Outlook - 文本输入 可见。

If I do the same - copy to clipboard, paste into Outlook - the text input is visible.

有什么办法可以拒绝吗? (无需告诉用户在Outlook中选择仅保留文字。)

Is there any way I can supress this? (Without resorting to telling users to select "Keep text only" in Outlook.)

谢谢!

推荐答案

听起来你需要让JavaScript创建DOM节,而不是改变CSS样式。而不是更改我是隐藏段落的显示属性,让JavaScript创建该元素,当你希望它显示,并删除它,你想要隐藏它。

It sounds like you need to have the JavaScript create the DOM sections rather than just changing CSS styles. Instead of changing the display property of the "I'm hidden" paragraph, have the JavaScript create that element when you want it to display, and remove it whan you want to hide it.

如果元素足够复杂,那么也许你可以在文档的底部使用display:none,但是将它们移动到你希望它们可见的位置。

If the elements are complicated enough, then perhaps you can have them at the bottom of the document with "display:none", but then move them into the place where you want them visible.

这篇关于“display:none”内容复制到剪贴板,粘贴时可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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