2013-04-23 71 views
0

当我尝试让这些动态地进行文字区域进入CEditor领域我得到的错误: 类型错误:B是未定义动态使得文本区域的CKEditor

我的代码:

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的:)

回答

0

我假设你正在使用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; 
+0

您不必分配它们的ID。你可以将元素传递给'CKEDITOR.replace'函数。 – Reinmar 2013-04-23 18:43:00

+0

感谢Reinmar,不需要id就可以做CKEDITOR.replace。从这个问题看来,用户似乎想分配它们并返回textarea对象,也许用户有其他想法。 – 2013-04-23 20:39:22

+0

我有一个窗口,用户可以放置多个文本区域 - 当这些文本区域放置或聚焦时,我想将它们变成ckeditor字段 - 当它们没有重点时,我想将它们更改回正常的textareas - 或者只是隐藏编辑菜单ckeditor耗材 – SimontheS 2013-04-24 07:10:41