动态添加tinymce到新的textarea

发布于 2025-01-01 02:09:09 字数 423 浏览 7 评论 0原文

我该怎么做

function addTinyText(id, text){
//add textarea to DOM
$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');
//init tineMCE
 tinyMCE.init({
        theme : "advanced",
        plugins : "emotions,spellchecker"
});
//add tinymce to this
tinyMCE.execCommand("mceAddControl", false, 'txt'+id);
}

,但结果每次我们有一个新的 textarea+tinyMCE 但里面没有文本

我错了什么?

How can i do this

function addTinyText(id, text){
//add textarea to DOM
$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');
//init tineMCE
 tinyMCE.init({
        theme : "advanced",
        plugins : "emotions,spellchecker"
});
//add tinymce to this
tinyMCE.execCommand("mceAddControl", false, 'txt'+id);
}

but as a result every time we have a new textarea+tinyMCE but no text inside

What do i wrong?

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

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

发布评论

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

评论(2

负佳期 2025-01-08 02:09:09

我搜索了很长时间才找到类似问题的答案。

即使我可以让编辑出现,我的内容也没有被发布。

我让它像这样工作:

    jQuery('.wysiwyg').tinymce({
      // Location of TinyMCE script
      script_url : 'path/tinymce/tiny_mce.js',

      // General options
      theme : "advanced",
     .........
     .........
     ......... etc

我使用标准 jquery 代码将类名为 wysiwyg 的所有文本区域启动为tinymce 对象。

ajax 调用完成并加载新的文本区域后,我运行此函数:

jQuery(".wysiwyg").each(function(){ 
    tinyMCE.execCommand("mceAddControl",false, this.id);
});

现在我的代码终于正确发布了。

I searched a very long time to find an answer to a similar problem.

My content was not being posted even thou I could get the editor to appear.

I got it working like this:

    jQuery('.wysiwyg').tinymce({
      // Location of TinyMCE script
      script_url : 'path/tinymce/tiny_mce.js',

      // General options
      theme : "advanced",
     .........
     .........
     ......... etc

I used the standard jquery code to initiate all text areas with class name wysiwyg as tinymce objects.

After ajax call completes and new textarea is loaded I run this function:

jQuery(".wysiwyg").each(function(){ 
    tinyMCE.execCommand("mceAddControl",false, this.id);
});

Now my code is finally being posted correctly.

总攻大人 2025-01-08 02:09:09

线

$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');

应该是线

$('<textarea id="txt'+id+'"></textarea>').text(text).appendTo('body');

line

$('<textarea id="txt'+id+'"></textarea>').append(text).appendTo('body');

should be line

$('<textarea id="txt'+id+'"></textarea>').text(text).appendTo('body');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文