Range.compareBoundaryPoints() method compares the boundary points of the 范围 with those of another range.

句法

compare = range.compareBoundaryPoints(how, sourceRange);
					

返回值

compare
A number, -1 , 0 ,或 1 , indicating whether the corresponding boundary-point of the 范围 is respectively before, equal to, or after the corresponding boundary-point of sourceRange .

参数

how
A constant describing the comparison method:
  • Range.END_TO_END compares the end boundary-point of sourceRange to the end boundary-point of 范围 .
  • Range.END_TO_START compares the end boundary-point of sourceRange to the start boundary-point of 范围 .
  • Range.START_TO_END compares the start boundary-point of sourceRange to the end boundary-point of 范围 .
  • Range.START_TO_START compares the start boundary-point of sourceRange to the start boundary-point of 范围 .

If the value of the parameter is invalid, a DOMException 采用 NotSupportedError code is thrown.

sourceRange
范围 to compare boundary points with the range.

范例

var range, sourceRange, compare;
range = document.createRange();
range.selectNode(document.getElementsByTagName("div")[0]);
sourceRange = document.createRange();
sourceRange.selectNode(document.getElementsByTagName("div")[1]);
compare = range.compareBoundaryPoints(Range.START_TO_END, sourceRange);
							

规范

规范 状态 注释
DOM
The definition of 'Range.compareBoundaryPoints()' in that specification.
实时标准 无变化。
Document Object Model (DOM) Level 2 Traversal and Range Specification
The definition of 'Range.compareBoundaryPoints()' in that specification.
过时 最初的规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
compareBoundaryPoints Chrome Yes Edge 12 Firefox 4 IE 9 Opera 9 Safari Yes WebView Android Yes Chrome Android Yes Firefox Android 4 Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: