简体   繁体   English

发布HTML Textarea或ContentEditable Div或其他内容。

[英]Post HTML Textarea Or ContentEditable Div or Something Else.

TEXTAREA can post HTML but we have to write HTML on in it while user doesn't know about html and Textarea does not allow short keys like Ctrl + B for bold. TEXTAREA可以发布HTML,但是我们必须在其中编写HTML,而用户不了解html,并且Textarea不允许使用Ctrl + B之类的短键来加粗。

CONTENTEDITABLE="True" property of Div element. Div元素的CONTENTEDITABLE =“ True”属性。 It allows writing HTML Code and Short Keys or any kind of HTML you copy from the other resource. 它允许编写HTML代码和短键或从其他资源复制的任何类型的HTML。

My is case is that i just want bold, italic, Underline and Enter Key. 我的情况是,我只想要粗体,斜体,下划线和Enter键。 if i use textarea it does not allow me short keys for edit the html andif i use contenteditable it gives me that features and so many others that i dont allow to user to post. 如果我使用textarea,则不允许我使用短键来编辑html;如果我使用contenteditable,则它为我提供了该功能以及许多其他我不允许用户发布的功能。

I am not going for the TinyMC BBCode and so on. 我不打算使用TinyMC BBCode等。 for the simple features like bold, italic, underline and enter. 粗体,斜体,下划线和输入等简单功能。

What should i do for that? 我该怎么办?

You need Javascript - Can div with contenteditable=true be passed through form? 您需要Javascript- 可以将contenteditable = true的div通过表格传递吗?

Code by smdrager from link above. smdrager从上面的链接进行编码。

<script type="text/javascript">
    function getContent(){
        document.getElementById("my-textarea").value = document.getElementById("my-content").innerHTML;
    }
</script>


<div id="my-content" contenteditable="true"><a href="page.html">Some</a> Text</div>

<form id="form" action="some-page.php" onsubmit="return getContent()">
    <textarea id="my-textarea" style="display:none"></textarea>
    <input type="submit" />
</form>

For allowing only some tags use this: http://phpjs.org/functions/strip_tags/ 要只允许某些标签,请使用以下代码: http : //phpjs.org/functions/strip_tags/

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

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