简体   繁体   English

Javascript:与tinyMCE一样,从textarea中使用html标记获取值

[英]Javascript: Get the value with the html tags from the textarea as with tinyMCE

When I am using TinyMCE, the value I am geting from is in HTML, also with HTML tags. 当我使用TinyMCE时,我从中获得的值是HTML,也带有HTML标签。 Is there a possibility to get the same from a textarea? 是否有可能从文本区域获得相同的信息?

When I am trying 当我尝试

var text= $('#myTextarea').val();

I am geting only the simple text, without html tags. 我只得到简单的文本,没有html标签。

Thank you for your help. 谢谢您的帮助。

you can use outerHTML property to get "tag source" 您可以使用externalHTML属性获取“标记源”

for simple input with id="inputId" you will get " <input type="text" id="inputId"> " 对于具有id =“ inputId”的简单输入,您将获得“ <input type="text" id="inputId">

in your case try 在你的情况下尝试

var text = $('#myTextarea')[0].outerHTML

It seems than the text and textarea are returning only plain text, and no html. 似乎text和textarea只返回纯文本,而不返回html。 We need to use tinyMCE in this case. 在这种情况下,我们需要使用tinyMCE。

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

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