如何在textarea中显示HTML格式? [英] How can I show HTML formatting inside a textarea?

查看:594
本文介绍了如何在textarea中显示HTML格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码可以让您使用粗体,下划线,删除线或斜体格式化textarea中的文本。但它显示html标签而不是实际格式化它。我知道一旦我在div中输出它,它就会被格式化,但我想在用户写文本时显示格式。

I have code that lets you format the text in a textarea with bold, underline, strikeout or italics. But it displays the html tags instead of actually formatting it. I know once I output it inside a div, it ill be formatted, but I want to show the formatting while the user writes the text.

如何启用格式化? JavaScript很好,我现在正在使用JQuery。如果还有其他选择,我也不愿使用WYSIWYG编辑器。

How can I enable formatting? JavaScript is fine, I'm using JQuery at the moment. I would also rather not use a WYSIWYG editor, if there is another option.

感谢您的帮助。

推荐答案

在div元素上使用contentEditable属性

Use contentEditable attribute on div element

 <div contentEditable="true"> 
 </div

这样你就可以用任何想要的方式格式化输入,只需不要忘记正确逃避数据。

This way you can format your input in any desired way, just dont forget properly escape data.

这篇关于如何在textarea中显示HTML格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆