How can I add rich text to a text area
Is there a way to set part of the text of the textarea with style. For example if i have a text area with this value:
Hi, how are you
I'd want this :
hi how are you
Setting the words that I want in bold and not all the values wrote in the text area. I would like开发者_高级运维 do it with jQuery maybe a plugin or something.
My text area:
<textarea id="txtMessageFields" cols="20" rows="2"></textarea>
You can use a WYSIWYG HTML editor for this purpose, like CKEditor or TinyMCE.
For example, with CKEditor's jQuery interface this is as easy as:
<script type="text/javascript" src="/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/ckeditor/adapters/jquery.js"></script>
<script type="text/javascript">
$(document.ready(function () {
$('#txtMessageFields').ckeditor();
});
</script>
from CKEditor jQuery Adapter Guide
Take a look at the configuration options to only enable the functionalities you need.
Try THIS its what you want. See the demo here
A <textarea>
element can only hold plain text:
- https://developer.mozilla.org/en/HTML/Element/textarea
As far as I know, all JavaScript WYSIWYG editors use a regular DOM node (an iframe or a div) and use regular HTML/CSS to get visual styles. You could write some code to dynamically replace your textarea but I assume it's a form field in the first place because it needs to be editable. If so, I suggest you pick a third-party editor. Here's quite a comprehensive list:
- http://geniisoft.com/showcase.nsf/WebEditors
As wrote bazmegakapa, you must use a WYSIWYG editor. From my experience, the best is TinyMCE, which includes a special package if you use jQuery (TinyMCE jQuery package).
精彩评论