问题描述
我正在寻找一种方法来复制一些div文本,使用JavaScript复制样式(斜体,字体系列,大小等),以便将其粘贴到Word中并与页面看起来一样。
I'm looking for a way to copy some div text with JavaScript copying the style (italics, font family, size, etc.) so I can paste it into Word and look the same as the page.
如果我想复制这段文字:
If I want to copy this text:
Hello world
我想粘贴为相同的而不是:
I want to paste as the same and not:
"<i>Hello</i> world"
我不知道如何感谢您的帮助
I don't know how and appreciate your help
推荐答案
好的,当您从网络浏览器复制文本时,您复制的只是文本。任何风格的设备都是Web浏览器的工作。
现在,在这种情况下,样式可以应用到Word文档中,所以您可以首先将没有样式的纯文本复制到Word中。
然后,你可以用你想要应用到这个文档中的所有样式来制作CSS文件(把你的所有样式分组到css文件中是一种很好的做法,而不是使用或等等.. )。
然后,您可以将此样式应用到文档中。现在,因为显然你的问题可能是:我如何将样式应用到文档中?,这里已经有关于此的讨论:
Well, when you copy text from a web browser, what you copy is only the text. The appliance of any style is job of the web browser.
Now, in this case though, styles can be applied into a Word document, so what you can is to first of all copy the plain text without the styles to Word.
Then, you can make CSS file with all the styles that you want to apply into this document(Grouping all your styles in css files is a generally good practice, instead of using or and so on..).
Then, you can apply this style into the document. Now because obviously your question might be: "How do I apply the style into the document?", there has already be done a discussion about that here: https://superuser.com/questions/65107/how-to-apply-external-css-stylesheet-to-document-in-microsoft-word
希望它有帮助!
这篇关于用字体样式复制到剪贴板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!