简体   繁体   English

使所选文本在 textarea 中变为粗体

[英]make the selected text bold in textarea

I have got two TextAreas and i want to use one toolbar.我有两个TextAreas ,我想使用一个工具栏。 The toolbar should contain buttons for making the text in the textbox bold, italic, align to the left and right, add bullet points etc.. What I don't get is: how can I make the selected text in the textarea bold ?工具栏应包含用于使文本框中的文本变为粗体、斜体、左右对齐、添加项目符号等的按钮。我不明白的是:如何使 textarea 中的选定文本变为粗体 I was using an iFrame before for writing text and used the iframe.contentDocument.execCommand() for that purpose.我之前使用 iFrame 来编写文本,并为此使用了iframe.contentDocument.execCommand() But I think we can not use the execCommand() for a TextArea.但我认为我们不能将 execCommand() 用于 TextArea。 To make it simple, I am just trying to make something like a TextArea which is identical to the TextArea when we post questions on stackoverflow, with a toolbar above it!为了简单起见,我只是想制作一个类似于 TextArea 的东西,当我们在 stackoverflow 上发布问题时,它与 TextArea 相同,上面有一个工具栏! But I don't know how to do operations on the text!但是我不知道如何对文本进行操作!

You cannot use textarea, because textarea can only contain character data, that is unstructured text .您不能使用 textarea,因为 textarea只能包含字符数据,即非结构化文本 Thus, all the contents of textarea have the same style.因此,textarea 的所有内容都具有相同的样式。

That's why CKEditor, TinyMCE etc. use iframes.这就是 CKEditor、TinyMCE 等使用 iframe 的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM