【发布时间】:2018-02-23 20:51:20
【问题描述】:
我有以下代码。 setContent 部分不起作用。如果我查看源代码,我可以看到来自 $rowpost["blog"] 的信息被放入页面中,只是由于某种原因没有显示。
<textarea name="txtBlog" id="txtBlog" cols="50" rows="10"></textarea>
<script type="text/javascript" src="https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=3x7na4p57b2ukuixfz5ird4sgs0kqhpfwzxlg0vz0j4dv4bd"></script>
<script>
tinymce.init({
selector:'textarea',
menubar:false,
plugins:[
'advlist autolink link lists image charmap print preview anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help'
],
toolbar:'styleselect | undo redo | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help'
})
tinymce.get("txtBlog").setContent('<?php echo $rowpost["blog"]; ?>');
</script>
感谢任何想法或建议。
谢谢
编辑
我将代码更改为此,但是当我刷新页面时,它将 textarea 更改回常规 textarea。但是,它会显示来自数据库的信息。
<textarea name="txtBlog" id="txtBlog" cols="50" rows="10"></textarea>
<script type="text/javascript" src="https://cloud.tinymce.com/stable/tinymce.min.js?apiKey=3x7na4p57b2ukuixfz5ird4sgs0kqhpfwzxlg0vz0j4dv4bd"></script>
<script>
tinymce.init({
selector:'textarea',
menubar:false,
plugins:[
'advlist autolink link lists image charmap print preview anchor textcolor',
'searchreplace visualblocks code fullscreen',
'insertdatetime media table contextmenu paste code help'
],
toolbar:'styleselect | undo redo | bold italic backcolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | removeformat | help'
setup: function (editor) {
editor.on('init', function () {
this.setContent("<?php echo $rowpost["blog"]; ?>");
});
}
})
</script>
【问题讨论】:
-
您检查浏览器控制台是否有错误?
-
您是否尝试过在没有 setContent 调用的情况下将您的 PHP 回显到 textarea 中?例如。
<textarea><?php echo $rowpost["blog"]; ?></textarea> -
没有错误,将数据加载到没有 tinyMce 的 textarea 会显示信息。
-
这不是你想要的吗?
-
当我说它变回常规文本区域时,它去掉了顶部用于编辑文本的 tinyMCE 栏。如果我取出 setup: function 部分,它会在顶部显示栏。
标签: javascript tinymce textarea