“显示:无” 内容已复制到剪贴板,粘贴时可见
我遇到了将未显示的 HTML 元素复制到剪贴板,然后在将内容粘贴到 MS Word、Outlook 等中时显示的问题。
例如:
<p>Hello</p>
<p style="display: none;">I'm Hidden</p>
<p>World</p>
如果我在浏览器中查看该 HTML,请将文本复制到我的剪贴板,然后粘贴到 Outlook 中,中间段落保持隐藏状态。 好消息。
但是,在此示例中:
<p>Hello</p>
<input type="text" value="I'm not hidden" style="display: none;" />
<p>World</p>
如果我执行相同操作 - 复制到剪贴板,粘贴到 Outlook 中 - 文本输入可见。
有什么办法可以抑制这种情况吗? (无需告诉用户在 Outlook 中选择“仅保留文本”。)
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
听起来您需要让 JavaScript 创建 DOM 部分,而不仅仅是更改 CSS 样式。 不要更改“我隐藏”段落的显示属性,而是让 JavaScript 在您希望显示该元素时创建该元素,并在您希望隐藏它时将其删除。
如果元素足够复杂,那么也许您可以使用“display:none”将它们放在文档的底部,然后将它们移动到您希望它们可见的位置。
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.
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.
使用 type='hidden' 而不是 type='text' 作为输入框,并将其包装在 div 中,样式设置为 display: none
Use type='hidden' instead of type='text' for the input box and wrap this inside a div with style set to display: none
您应该知道,仅当渲染器支持所有 CSS 样式时,使用 CSS 隐藏 HTML 才有效。
仅仅因为您在 Outlook 中没有看到复制/粘贴的 HTML,并不意味着数据不存在。
我不确定您实际上想要实现什么:为什么您需要用户将 HTML 复制到 Outlook 中?
You should be aware that hiding HTML with CSS only works if the renderer supports all the CSS styles.
Just because you do not see copy/pasted HTML in Outlook does not mean the data is not already there.
I am not sure what you are actually trying to achieve: Why do you need your users to copy HTML into Outlook at all?
如果您要求用户复制内容,我建议将该内容放入
If you require users to copy content, I'd recommend dropping that content in a <textarea /> and allowing them to select/copy by clicking a button. It can be difficult to select exactly the right text in browsers.
这是我用来解决这个问题的解决方案。
策略:
以下是一些注意事项:
whereHiddenThingsLive.find('.some-class')
。代码:
Here is the solution I used to work around it.
The strategy:
Here are some notes:
whereHiddenThingsLive.find('.some-class')
.The code: