Range.toString() - Web APIs 编辑
The Range.toString()
method is a stringifier returning the text of the Range
.
Alerting the contents of a Range
makes an implicit toString()
call, so comparing range and text through an alert dialog is ineffective.
Syntax
text = range.toString();
Example
HTML
<p>This example logs <b>everything</b> between the bold <b>words</b>. Look at the output below.</p>
<p id="log"></p>
JavaScript
const range = document.createRange();
range.setStartBefore(document.getElementsByTagName('b').item(0), 0);
range.setEndAfter(document.getElementsByTagName('b').item(1), 0);
document.getElementById('log').textContent = range.toString();
Result
Specifications
Specification | Status | Comment |
---|---|---|
DOM The definition of 'Range.toString()' in that specification. | Living Standard | No change. |
Document Object Model (DOM) Level 2 Traversal and Range Specification The definition of 'Range.toString()' in that specification. | Obsolete | Initial specification. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论