Range:toString() 方法
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since March 2017.
语法
js
toString()
参数
无。
返回值
字符串。
示例
HTML
html
<p>此示例记录了强调<em>字</em>之间的<em>所有</em>内容。请看下面的输出结果。</p>
<p id="log"></p>
JavaScript
js
const range = document.createRange();
range.setStartBefore(document.getElementsByTagName("em").item(0), 0);
range.setEndAfter(document.getElementsByTagName("em").item(1), 0);
document.getElementById("log").textContent = range.toString();
结果
规范
Specification |
---|
DOM Standard # dom-range-stringifier |
浏览器兼容性
BCD tables only load in the browser