一个很全面的html dom API https://developer.mozilla.org/en-US/docs/Web/API/Selection
Selection is the class of the object returned by window.getSelection() and
other methods. It represents the text selection in the greater page, possibly
spanning multiple elements, when the user drags over static text and other parts
of the page. For information about text selection in an individual text editing
element, see Input, TextArea anddocument.activeElement which
typically return the parent object returned fromwindow.getSelection().
selection是通过window.getSelection()或者其他方法返回的一个对象。当用户拖拽了静态文字或者网页的其他部分的时候,它描述了在整个页面的文本选择,很可能跨越了多个dom元素。对于可编辑的元素而言,比如input,textarea,document.activeElement,通过window.getSelection方法,将返回其父对象的Range。
The Range interface represents a
fragment of a document that can contain nodes and parts of text nodes in a given
document.
A range can be created using the createRange method
of the Document object.
Range objects can also be retrieved by using the getRangeAt method
of the Selection object.
Range是一个描述包含了dom节点或者部分文本的一个接口对象(我也不知道怎么翻译。。。)。它可以通过document.createRange()方法去创建。另外,它也可以通过window.getSelection().getRangeAt(0)的方式获取。
Other key terms used in this section.
range object.
Range objects can also be created via the DOM and programmatically added or
removed from a selection.Range API
Range.collapsed Read
onlyReturns a Boolean indicating
whether the range‘s start and end points are at the same
position.如果开始和结束在同一位置,返回true
Range.commonAncestorContainer Read
onlyReturns the deepest Node that
contains
the startContainer and endContainer nodes.返回被继承的容器,它包含了startContainer
和 endContainer 节点。
Range.endContainer Read
onlyReturns the Node within
which the Range ends.返回Range结尾所在的dom节点。
Range.endOffset Read
onlyReturns a number representing where in
the endContainer the Range ends.返回一个数字,它描述了在endContainer 中,range的终止位置。
Range.startContainer Read
onlyReturns the Node within
which the Range starts.返回了Range开始所在的dom节点。
Range.startOffset Read
onlyReturns a number representing where in
the startContainer the Range starts.返回一个数字,它描述了在startContainer 中,range的起始位置。
Methods
Range.setStart()Sets
the start position of a Range.
Range.setEnd()Sets
the end position of a Range.
Range.setStartBefore()Sets
the start position of a Range relative to another Node.
Range.setStartAfter()Sets
the start position of a Range relative to another Node.
Range.setEndBefore()Sets
the end position of a Range relative to another Node.
Range.setEndAfter()Sets
the end position of a Range relative to another Node.
Range.selectNode()Sets
the Range to contain the Node and
its contents.
Range.selectNodeContents()Sets
the Range to contain the contents of a Node.
Range.collapse()Collapses
the Range to one of its boundary points.
Range.cloneContents()Returns
a DocumentFragment copying
the nodes of a Range.
Range.deleteContents()Removes
the contents of a Range from the Document.
Range.extractContents()Moves
contents of a Range from the document tree into a DocumentFragment.
Range.insertNode()Insert
a Node at
the start of a Range.
Range.surroundContents()Moves
content of a Range into a new Node
Range.compareBoundaryPoints()Compares
the boundary points of the Range with another one.
Range.cloneRange()Returns
a Range object with boundary points identical to the
cloned Range.
Range.detach()Releases
the Range from use to improve performance.
Range.toString()Returns
the text of the Range.
Selection API
anchorNodeanchorOffsetfocusNodefocusOffsetisCollapsedrangeCountgetRangeAtcollapseextendmodifycollapseToStartcollapseToEndselectAllChildrenaddRangeremoveRangeremoveAllRangesdeleteFromDocumentselectionLanguageChangetoStringcontainsNode原文:http://www.cnblogs.com/crowley/p/3592771.html