html textarea how to apply styles on content within the textarea
I know that this topic has been discussed since I can see traces on the web. The consense seems to be that it is impossible. But I know on at least one product (TinyMCE) which manages to do it. Note: I do not want to use 开发者_如何学JAVATinyMCE to do it.
I want to add some icons to the text content of the textarea element. It would be great if one could click on the icons as well.
Maybe somebody here already looked into TinyMCE and knows how they do it. Is this done using Javascript? Or is this some browser specific browser mechanism like spell check?
From my understanding libraries like this use a contentEditable
div. This allows for textarea-like editing as well as html elements.
TinyMCE hides the textarea and replaces it in the document with an iframe whose content is editable (using either the designMode
property of the iframe's document or the contentEditable
property of the iframe's <body>
element). I believe the textarea is still kept in the document and its value updated as the user edits content in the editable iframe so that the HTML produced by TinyMCE is submitted as though it had been entered into the textarea.
精彩评论