Programmeren
XML DOM compareBoundaryPoints() methode
Definitie en gebruik
De compareBoundaryPoints() methode vergelijkt de positie van twee bereiken.
syntaxis:howcompareBoundaryPoints(sourceRange,
)
) | description |
---|---|
how | parameter |
sourceRange | te vergelijken met het bereik dat moet worden vergeleken. Het bepaalt hoe de vergelijking moet worden uitgevoerd (dus welke grenspunten worden vergeleken). Zijn geldige waarden zijn de constanten die worden gedefinieerd door de Range-interface. |
terugwaarde
als de gespecificeerde grenspunten van de huidige reeks zich bevinden sourceRange voor het specifieke grenspunt, wordt -1 geretourneerd. Als de twee gespecificeerde grenspunten hetzelfde zijn, wordt 0 geretourneerd. Als de grenspunten van de huidige reeks zich bevinden sourceRange na het specifieke grenspunt, wordt 1 geretourneerd.
uitwerpen
Als sourceRange represents a document different from the document represented by the current range, and this method will throw an error code of WRONG_DOCUMENT_ERR. DOMException exception.
description
This method will compare the boundary points of the current range and the specified sourceRange boundary points and returns a value that declares their relative position in the source document. The parameter how specifies which boundary point of two ranges to compare. The valid values of this parameter and their meanings are as follows:
- Range.START_TO_START - Compare the start points of two Range nodes
- Range.END_TO_END - Compare the end points of two Range nodes
- Range.START_TO_END - Using sourceRange start point compared to the end point of the current range
- Range.END_TO_START - Using sourceRange end point compared to the start point of the current range
The return value of this method is a number that declares the relative position of the current range to sourceRange location. Therefore, you may think that you first need to use the parameter how range constants specify the boundary points of the current range, and then use it to specify sourceRange boundary points. In fact, the constant Range.START_TO_END specifies the boundary points of the current range with the end point of the current range and sourceRange for comparison. Similarly, the constant Range.END_TO_START specifies the comparison of the start point of the current range with the end point of the specified range.