Selection.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.
Selection.toString()
方法返回 selection 对象当前代表的字符串。例如,当前选中的文本。
语法
js
toString()
参数
无。
返回值
selection 对象代表的字符串。
描述
此方法返回当前被选中的文本。
在 JavaScript 中,当 selection 对象作为字符串类型传递给函数时,此方法会被自动调用:
js
alert(window.getSelection()); // 被调用时
alert(window.getSelection().toString()); // 真实情况
规范
Specification |
---|
Selection API # dom-selection-stringifier |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
toString |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
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.
参考
- 属于
Selection
接口。