0

我在我的网站上使用 Aloha 编辑器。我已经能够成功使用它,用户可以创建 HTML 并将其保存到我的数据库中。但是,我在将 HTML 内容预加载到编辑器中以便用户可以编辑现有 HTML 时遇到问题。

这是初始化编辑器的 Javascript:

<script type="text/javascript">
Aloha.ready(function () {
    Aloha.jQuery('#richTextEditor').aloha();
    Aloha.bind('aloha-smart-content-changed', function (event, editable) {
        $(".hiddenTextArea").val(Aloha.getActiveEditable().getContents());
        $("#btnSave").click();
    });
    var obj = "";
    Aloha.activeEditable().setContents($(".hiddenTextArea").val(), obj);
});
</script>

我曾尝试使用 Aloha.activeEditable().setContents(),因为我在另一个网站上看到了这一点,但我的浏览器出现错误提示

Error: TypeError: Aloha.activeEditable is not a function
4

2 回答 2

0

Rene 的回答是正确的,但我发现还有第二种方法可以用数据预先填充 Aloha 编辑器。您可以简单地将文本添加到将 Aloha 编辑器定位到的 HTML 元素(在我的情况下为 #richTextEditor),然后调用 Aloha.bind()。

于 2013-06-19T12:10:36.453 回答
0

啊哈!

它是

/**
 * Set the contents of this editable as a HTML string
 * @param content as html
 * @param return as object or html string
 * @return contents of the editable
*/
Aloha.activeEditable.setContents('your html string', true);

不是

Aloha.activeEditable().setContents();

你看过这个例子吗: http: //aloha-editor.org/howto-store-data-with-aloha-editor-ajax.php

您不需要将内容写入文本区域。如果您需要表单中具有其他值的内容,您也可以通过 AJAX 直接提交它,或者直接 .aloha() textarea 提交(使用 textarea 时请注意:如果 textarea 的 html id 为“xy”,则 id 为Aloha 编辑器中的可编辑将是“xy-aloha”)

您真的希望在每个“aloha-smart-content-changed”事件中发送表单吗?也许使用'aloha-editable-deactivated'?'aloha-smart-content-changed' 不会被触发,例如当某些东西被格式化为粗体...

于 2013-06-18T20:07:59.280 回答