繁体   English   中英

Ckeditor getSelectedElement始终为null

[英]Ckeditor getSelectedElement always null

我正在尝试在Ckeditor中获取选定的元素。 即如果html是:

This has <a href="www.google.com">a link</a>.

我想检索整个a时,我选择链接文本元素。

据我了解,以下代码:

editor.getSelection().getSelectedElement()

应该这样做。 但是它总是返回null(无论我选择的是多少)。 我尝试了其他各种元素类型,结果始终相同。

getSelection()本身不返回null。 我可以只获得链接文本

editor.getSelection().getNative().toString().

我什至尝试了一些在这里找到的旧代码:

http://cksource.com/forums/viewtopic.php?f=6&t=11997&p=31833

但这导致错误Object #<Object> has no method 'getRangeAt'

有没有人有什么建议?

我也对同一件事进行故障排除。 但是使此代码正常工作。 只要检查是否有帮助

var element = CKEDITOR.plugins.link.getSelectedLink( editor );
    if ( element )
    {
       if ( element.is( 'a' ) )
       {
          var urldata = element.getAttribute( 'href' );
          this.setValue(urldata);
        }
       }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM