[英]Use getContent from multiple TinyMCE4 instances in one go?
I need to get the HTML from a sourrounding DIV, and at the same time get the correct (raw?) HTML from the multiple DIVs with the inline tinyMCE4. 我需要从环绕的DIV中获取HTML, 同时使用内联的tinyMCE4从多个DIV中获取正确的(原始的)HTML 。
I have managed to get all the HTML by using : 我设法通过使用获取所有的HTML:
jQuery("#ForSaving").html(jQuery(".Editable").html());
But this gets the wrong HTML from the tinyMCE. 但这会从tinyMCE中获取错误的HTML。 In stead of a output of for instance <iframe>
, I get a <img class="mce-object mce-object-iframe"
etc. 代替例如<iframe>
的输出,我得到了<img class="mce-object mce-object-iframe"
等。
I have tried to use tinyMCE's getContent()
, but have not succeeded to get the correct from all tinyMCE instances in one go. 我尝试使用tinyMCE的getContent()
,但一次也没有成功从所有tinyMCE实例中获取正确的内容。
It is important to me that I don't only get the content from inside the tinyMCE DIVs, but also the surrounding DIVs and code . 对我来说重要的是,我不仅从tinyMCE DIV内部获取内容,而且从周围的DIV和代码中获取内容。 I need that to further process the HTML. 我需要它来进一步处理HTML。
Here is an example of my pure HTML: 这是我的纯HTML的示例:
<html>
<head>
<script type="text/javascript">
tinymce.init({
selector: "div.tinyeditor",
inline: true,
theme: "modern",
</script>
</head>
<body>
<div id="ForSaving"></div>
<div id="Editable">
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor"><p>The HTML inside tinyMCE</p></div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor"><p>The HTML inside tinyMCE</p></div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor"><p>The HTML inside tinyMCE</p></div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor"><p>The HTML inside tinyMCE</p></div>
</div>
</div> <!-- end of div#editable -->
</body>
</html>
I need to get ALL the HTML content from within the DIV #Editable, but with the (raw?) correct HTML output from the tinyMCE instances. 我需要从DIV #Editable中获取所有HTML内容,但要从tinyMCE实例获得(原始?)正确的HTML输出。 Hopefully at once. 希望立刻。
I need to get a HTML looking like this: 我需要获取如下所示的HTML:
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor">(THE REAL HTML FROM tinyMCE)</div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor">(THE REAL HTML FROM tinyMCE)</div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor">(THE REAL HTML FROM tinyMCE)</div>
</div>
<div class="contentwrap" id="area_(randnumb)">
<div class="somediv">Some html</div>
<div class="tinyeditor">(THE REAL HTML FROM tinyMCE)</div>
</div>
</div>
Is there a simple way to do this? 有没有简单的方法可以做到这一点?
I solved this by doing some changes: 我通过做一些更改解决了这个问题:
1) I used jquery each() to run a loop through each div.contentwrap 1)我使用jquery each()在每个div.contentwrap中运行一个循环
2) I first got the contentwrap's true ID 2)我首先得到了contentwrap的真实ID
3) Then built the usin var contentwrapstart = (and using HTML + the ID here) 3)然后构建usin var contentwrapstart =(并在此处使用HTML + ID)
<div class="contentwrap" id="area_(randnumb)">
4) Then got the tinyMCE content for that specific tinyeditor. 4)然后获得该特定tinyeditor的tinyMCE内容。 (Had to add a ID to that div too) (也必须向该div添加ID)
5) Then built < to end the wrapping 5)然后构建<以结束包装
6) Added each to a var result += (values here) 6)将每个值添加到var结果+ =(此处为值)
7) Did this for each 7)是否每个
8) Stored var result = outside the loop 8)存储的var结果=循环外
9) Got the HTML I needed from var result later. 9)稍后从var结果中获取了我需要的HTML。
And this worked well :-) 这很好用:-)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.