2011-02-15 51 views
0

我正在使用ckeditor,并且我们构建了一个定制插件来定义页面上锚点的链接。现在,当我尝试让我的页面上的所有锚点都没有返回。获取ckeditor文档中的锚点

我的HTML如下所示:

<p> 
    <a name="anchor-anchor"></a></p> 

但是,当我试图让文档中的所有锚这样的:返回
editor.document.getElementsByTag("a")

什么。但是,当我放置一个正常的锚点上面的代码会发现。 我做错了什么?

问候!

回答

3

这是直接从链接对话框:

// Find out whether we have any anchors in the editor. 
    // Get all IMG elements in CK document. 
    var elements = editor.document.getElementsByTag('img'), 
     realAnchors = new CKEDITOR.dom.nodeList(editor.document.$.anchors), 
     anchors = retval.anchors = []; 

    for (var i = 0; i < elements.count() ; i++) 
    { 
     var item = elements.getItem(i); 
     if (item.data('cke-realelement') && item.data('cke-real-element-type') == 'anchor') 
      anchors.push(editor.restoreRealElement(item)); 
    } 

    for (i = 0 ; i < realAnchors.count() ; i++) 
     anchors.push(realAnchors.getItem(i)); 

    for (i = 0 ; i < anchors.length ; i++) 
    { 
     item = anchors[ i ]; 
     anchors[ i ] = { name : item.getAttribute('name'), id : item.getAttribute('id') }; 
    }