【问题标题】:dynamically making textarea ckeditor动态制作 textarea ckeditor
【发布时间】:2013-04-23 13:19:43
【问题描述】:

当我尝试将这些动态生成的文本区域放入 CEditor 字段时,我收到错误消息: 类型错误:b 未定义

我的代码:

    var input = $("<textarea>").addClass("textAreaClassTest");
    //input.setAttribute("id", "como");
    //input.setIdAttribute("id", "como");
    //input.ID = 'como';
    CKEDITOR.replace('como');
    item.append(input);
    //CKEDITOR.replace('como');

    return item;

我似乎无法给 textarea 一个 id - 任何 id 的 :)

【问题讨论】:

    标签: textarea ckeditor undefined


    【解决方案1】:

    我假设您使用的是 jQuery,并且一次只能处理 1 个或多个文本区域。因此,您可以获取文本区域并为其分配 id 并按如下方式使用它们。

    //select all text areas
    var input = $("textarea");
    var list = new Array();
    var count = 0;
    
    input.each(function () {
        count++;
        $this = $(this);
        $this.attr("id", "como" + count);
        console.log('id is "' + $this.attr("id") + '" and text is "' + $this.text() + '"');
        CKEDITOR.replace($this.attr("id"));
        list.push($this.attr("id"));
    });
    //return the list of replaced text area ids
    return list;
    

    【讨论】:

    • 您不必为它们分配 ID。您可以将元素传递给CKEDITOR.replace 函数。
    • 感谢 Reinmar,不需要 id 来执行 CKEDITOR.replace。从问题来看,用户似乎想为他们分配 id 并返回 textarea 对象,也许用户有别的想法。
    • 我有一个窗口,用户可以在其中放置多个文本区域 - 当这些文本区域被放置或聚焦时,我想将它们变成 ckeditor 字段 - 当它们不聚焦时,我想将它们改回普通文本区域 - 或者只是隐藏 ckeditor 提供的编辑菜单
    • 但我仍然无法让新放置的文本区域变成 ckeditors
    • 你能解释一下代码的哪一部分不工作或粘贴一些你在做什么的例子吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-15
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 2015-10-04
    • 1970-01-01
    相关资源
    最近更新 更多