[英]Load TinyMCE using innerHTML in PHP
Based on a selected option the code prints an textarea on the complemento1 div:根据选定的选项,代码会在补全 1 div 上打印一个textarea :
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:现在我想添加一个 TinyMCE 编辑器,但我的尝试失败了,我尝试将代码放在 PHP 文件中:
<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:尽管“模式:textareas”没有任何反应......如果我在我的代码中调用init:
<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! ^^^ 它已经在我的 PHP 上定义了! ( at head) (在头)
Where did I go wrong?我哪里做错了? How can I define TinyMCE correctly?如何正确定义 TinyMCE?
First try to load tinymce in the beginning and try to open it to check if exist首先尝试在开始时加载tinymce并尝试打开它以检查是否存在
<script src="/_assets/editor/vendor/tinymce/tinymce/tinymce.min.js"></script>
or try to run your JS after loading code :或尝试在加载代码后运行您的 JS:
$('#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 功能
$( 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})
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.