文本选择API去哪里了?



两年前,HTML5标准删除了包含Selection接口规范的"Text Selection API"一章:

[Stringifies] interface Selection {
  readonly attribute Node anchorNode;
  readonly attribute long anchorOffset;
  readonly attribute Node focusNode;
  readonly attribute long focusOffset;
  readonly attribute boolean isCollapsed;
  void collapse(in Node parentNode, in long offset);
  void collapseToStart();
  void collapseToEnd();
  void selectAllChildren(in Node parentNode);
  void deleteFromDocument();
  readonly attribute long rangeCount;
  Range getRangeAt(in long index);
  void addRange(in Range range);
  void removeRange(in Range range);
  void removeAllRanges();
};

请看这里:http://www.w3.org/TR/2009/WD-html5-20090423/editing.html#selection

我记得在另一个标准中遇到过这个接口,但是我忘了是哪个了。谁能帮我回忆一下吗?

它转移到WHATWG的DOM范围规范。该文档的范围部分最近(在上周左右)迁移到W3C的DOM4规范。

这使得WHATWG范围规范处于相当具有误导性的位置。我不确定是否有计划再次移动选择功能,但我不会打赌它不会。

2013年2月更新

规范的选择部分目前在HTML编辑api规范中找到。

最新更新