html Selection
一個很全面的html dom API?https://developer.mozilla.org/en-US/docs/Web/API/Selection
Introduction(簡介)
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)的方式獲取。
Glossary(術語)
Other key terms used in this section.
anchorRange API
Properties
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
Properties
anchorNodeMethods
getRangeAt轉載于:https://www.cnblogs.com/crowley/p/3592771.html
總結
以上是生活随笔為你收集整理的html Selection的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 重新想象 Windows 8 Store
- 下一篇: java中的final, finally