简体   繁体   English

Ckeditor getSelectedElement始终为null

[英]Ckeditor getSelectedElement always null

I am trying to get the selected element in Ckeditor. 我正在尝试在Ckeditor中获取选定的元素。 Ie if the html is: 即如果html是:

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

I want to retrieve the entire a element when I select the link text. 我想检索整个a时,我选择链接文本元素。

As I understand it the following code: 据我了解,以下代码:

editor.getSelection().getSelectedElement()

is supposed to do that. 应该这样做。 But it is always returning null (no matter how much or how little I select). 但是它总是返回null(无论我选择的是多少)。 I have tried various other element types and the result is always the same. 我尝试了其他各种元素类型,结果始终相同。

getSelection() by itself is not returning null. getSelection()本身不返回null。 I am able to get just the link text with 我可以只获得链接文本

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

I even tried some old code that I found here: 我什至尝试了一些在这里找到的旧代码:

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

but that resulted in the error Object #<Object> has no method 'getRangeAt' 但这导致错误Object #<Object> has no method 'getRangeAt'

Does anyone have any suggestions? 有没有人有什么建议?

I was too troubleshooting the same thing. 我也对同一件事进行故障排除。 But got this code working. 但是使此代码正常工作。 Just check if it helps 只要检查是否有帮助

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