求教各位大神,如题
<div id="editor" contentEditable="true">
    ...
</div>
这个div块里有很多内容,当将编辑位置指向某一个内容时,也即光标置于里面某个内容块时,
怎么获取这个块是什么节点呢?

解决方案 »

  1.   

    我也遇到相同问题
    let element = this.getDomWithEventtarget;
        var doc = element.ownerDocument || element.document;
        var win = doc.defaultView || doc.parentWindow;
        var sel;
        if (typeof win.getSelection != "undefined") {
          //谷歌、火狐
          sel = win.getSelection();
          if (sel.rangeCount > 0) {
            //选中的区域
            var range = win.getSelection().getRangeAt(0);
            return range.endContainer.parentElement;
          }
        }
    这种方法 取值偶尔不准, 请问你最后是怎么解决的
      

  2.   

    用委托和focus事件试试