dongni9825 2019-02-21 13:54
浏览 154
已采纳

在PHP中使用innerHTML加载TinyMCE

Based on a selected option the code prints an textarea on the complemento1 div:

        if ($_GET["t"]==1) /// Text
    {
        $str="";
        $str.="<table width=100%>";
            $str.="<tr>";
                $str.="<td>";
                    $str.="Digite aqui o texto que será exibido:";
                $str.="</td>";
            $str.="<tr>";
                $str.="<td>";
                    $str.="<textarea id='texto' name='texto' rows=3 cols=80>".$row["texto"]."</textarea>";
                $str.="</td>";
        $str.="</table>";
        echo "<script>window.parent.document.getElementById('complemento1').innerHTML=\"".$str."\";</script>";
    }

Now I want to add an TinyMCE editor, but my attempts failed, I've tried to put the code on the PHP file:

    <script src="/_assets/editor/vendor/tinymce/tinymce/tinymce.min.js"></script>
    <script type="text/javascript">tinymce.init({mode: 'textareas', language: 'pt_BR', menubar: '', statusbar: false});</script>

Despite "Mode: textareas" nothing happens... If I call the init inside my code:

<script>window.parent.document.getElementById('complemento1').innerHTML=\"".$str."\"; tinymce.init({mode: 'textareas', language: 'pt_BR', menubar: '', statusbar: false});</script>

Got the error on the console:

Uncaught ReferenceError: tinymce is not defined
at 

^^^ It is already defined on my PHP! ( at head)

Where did I go wrong? How can I define TinyMCE correctly?

  • 写回答

1条回答 默认 最新

  • doujiao4705 2019-02-21 15:56
    关注

    First try to load tinymce in the beginning and try to open it to check if exist

    <script src="/_assets/editor/vendor/tinymce/tinymce/tinymce.min.js"></script>

    or try to run your JS after loading code :

    $('#complemento1').html(\"".$str."\").promise().done(function( arg1 ) {
      //  try fire the event here  
     tinymce.init({mode: 'textareas', language: 'pt_BR', menubar: '', statusbar: false})
    });
    

    you can also try to add document.ready function

    $( document ).ready(function() {
        $('#complemento1').html(\"".$str."\").promise().done(function( arg1 ) {
         //  try fire the event here  
        tinymce.init({mode: 'textareas', language: 'pt_BR', menubar: '', statusbar: false})
        });
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 网络科学导论,网络控制
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)