TinyMCE 在隐藏文本区域之前不会从文本区域获取内容

发布于 2024-12-23 17:52:50 字数 1433 浏览 1 评论 0原文

我在页面上运行了一个 TinyMCE 实例,使我能够编辑现有帖子。我查询数据库,并使用存储的文本填充变量 $content 。然后我有以下 HTML:

<label for="content">Content:</label>
<textarea name="content" class="post-content" rows="<?php echo $settings_rows; ?>" ><?php echo $content; ?></textarea>

TinyMCE 正在显示为编辑器,没有问题,但不显示存储在 $content 中的文本。没有外围

标签,并且 $content 变量正在被填充(我在文本区域之外回显了它,以确保Firebug显示了隐藏的文本区域也被填充)。

编辑器 init 如下:

    tinyMCE.init({
            mode : "textareas",
            theme : "advanced",
            plugins : "advimage",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,image,hr,removeformat,visualaid,charmap,code",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_resizing : true,
            editor_selector : "post-content"
    });

谁能告诉我为什么这不起作用?我已经在其他页面上使用过它,使用这个确切的系统,没有出现任何问题。

编辑

作为 PS,相关 CSS 如下:

.post-content {
padding: 3px 10px;
width: 90%;
}

I have an instance of TinyMCE running on a page that enables me to edit existing posts. I query the db, and populate the variable $content with the stored text. I then have the following HTML:

<label for="content">Content:</label>
<textarea name="content" class="post-content" rows="<?php echo $settings_rows; ?>" ><?php echo $content; ?></textarea>

TinyMCE is displaying as an editor, no problem, but is not displaying the text stored in $content. There are no outlying <p> tags, and the $content variable is being populated (I echo'd it outside of the textarea to be sure, and Firebug shows the hidden textarea also being populated).

The editor init is as follows:

    tinyMCE.init({
            mode : "textareas",
            theme : "advanced",
            plugins : "advimage",
            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,sub,sup,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
            theme_advanced_buttons2 : "cut,copy,paste,pastetext,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,|,image,hr,removeformat,visualaid,charmap,code",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            theme_advanced_resizing : true,
            editor_selector : "post-content"
    });

Can anyone advise me why this isn't working? I've used it on other pages, using this exact system, without a hitch.

EDIT

As a P.S. the relevant CSS is as follows:

.post-content {
padding: 3px 10px;
width: 90%;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠佳期 2024-12-30 17:52:50

尝试以下操作。为您的文本区域指定 ID“editor1”,使用 mode: "exact", 而不是 mode: "textareas",
并按以下方式初始化编辑器(暂时将tinymce init保留在原来的位置,但在以下几行之前)

$(document).ready(function() {
    tinyMCE.execCommand('mceAddControl', false, 'editor1');
}

Try the following. Give your textarea the id "editor1", use mode: "exact", instead of mode: "textareas",
and initialize your editor the following way (keep the tinymce init where it is for now, but before the following lines)

$(document).ready(function() {
    tinyMCE.execCommand('mceAddControl', false, 'editor1');
}
违心° 2024-12-30 17:52:50

如果有人使用 HTML5 并且遇到 TinyMCE 行为类似或如标题中所述:尝试禁用自动完成。

<textarea autocomplete="off">Hello, World!</textarea>

如果您更改/清除页面上的文本区域内容,您的浏览器将在您每次重新加载页面时复制这些更改(启用自动完成功能)。
这会使 TinyMCE 看起来好像没有处理文本区域内容。

In case someone uses HTML5 and is experiencing TinyMCE behaving similar or as described in the title: Try disabling autocomplete.

<textarea autocomplete="off">Hello, World!</textarea>

If you change/clear the textarea content on the page, your browser will copy those changes every time you reload the page (with autocomplete enabled).
This can make it look as if TinyMCE isn't processing the textarea content.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文