简体   繁体   English

tinyMCE setContent条带关闭p标签

[英]tinyMCE setContent strips closing p-tag

i want to put the content from a database field to the tinyMCE editor on page load. 我想在页面加载时将数据库字段中的内容放到tinyMCE编辑器中。 For that i've got a php function like this: 为此,我有一个像这样的php函数:

public function __loadTinyMCE($jobscopeIntroText) {
    print '
    <script type="text/javascript">
        function loadDefaultTinyMCEContent(){
             tinyMCE.activeEditor.setContent("'.$jobscopeIntroText.'", {format : "raw"});
        }
    </script>
    ';

$jobscopeIntroText is the html content i previously wrote into the tinyMCE editor and comes from the database. $jobscopeIntroText是我以前写到tinyMCE编辑器中的html内容,来自数据库。

When i write eg: 当我写例如:

<p>Hello< /p>< p>This is a new line< /p>

it doesnt work and the html code in setContent() is broken after the first closing p-tag. 它不起作用, setContent()的html代码在第一个关闭的 p标签之后中断。 In chrome developer tools the text before the first closing p-tag is red and after that it's black. 在chrome开发人员工具中,第一个闭合p-tag之前的文本为红色,之后为黑色。 Even if there are no " or ' within the html. With only one closing p-tag it works. 即使html中没有“或”,也只能使用一个关闭的p标签。

Anyone knows the problem here? 有人知道这里的问题吗?

I think you should use this code once all contents will be loaded. 我认为一旦所有内容都将加载,就应该使用此代码。 Therefore there can be ways to achieve desire result: 因此,可以有一些方法来达到期望的结果:

  1. You can place your database value within editor element and then initialize tinyMCE editor. 您可以将数据库值放置在editor元素中,然后初始化tinyMCE编辑器。 (if page is loading) (如果页面正在加载)
  2. You can above function just before the before the body tag ends. 您可以在body标签结束之前之前执行上述功能。
  3. You can use document load event or jQuery document.ready() function and just function within it. 您可以使用文档加载事件或jQuery document.ready()函数,也可以在其中使用。

I hope this will work for you. 希望这对您有用。 Please do let me know for specific scenario. 对于特定情况,请务必让我知道。

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

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