简体   繁体   English

JavaScript execcommand是否可以与textarea一起使用?

[英]Does JavaScript execcommand works with textarea?

I want to know if JavaScript execcommand works with textarea. 我想知道JavaScript execcommand是否可与textarea一起使用。 In IFrame it works but in textarea it seems not... Thank! 在IFrame中,它可以工作,但在textarea中,似乎不行。

If it is for the purpose of editing some rich content, I don't think that will be possible, as a textarea support text only and does not display HTML as anything but plain text. 如果出于编辑某些丰富内容的目的,我认为这是不可能的,因为textarea仅支持文本,并且除了纯文本之外不显示HTML。 You could however use a div element, and apply it to that instead. 但是,您可以使用div元素,然后将其应用于该元素。

If you need to post the HTML somewhere, and that is the reason you want to put it on a textarea, I guess you could use a div for the editor, and then copy the content of the div to a hidden input, whenever the content changes. 如果您需要将HTML发布到某个地方,那就是您要将其放在文本区域的原因,我想您可以使用div作为编辑器,然后在任何时候将div的内容复制到隐藏的输入中变化。 You could then use the hidden input to post the HTML. 然后,您可以使用隐藏的输入来发布HTML。

The documentation on MDN has an example of a rich text editor that uses a div . MDN文档中有一个使用div的富文本编辑器示例。

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

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