Selection: toString() 方法
Selection.toString() 方法返回由 selection 对象当前表示的字符串,即当前选中的文本。
语法
js
toString()
参数
无。
返回值
表示选中的字符串。
描述
此方法返回当前选中的文本。
在 JavaScript 中,当一个需要字符串的选择对象被传递给某个函数时,此方法会被自动调用。
js
alert(window.getSelection()); // What is called
alert(window.getSelection().toString()); // What is actually being effectively called.
规范
| 规范 |
|---|
| Selection API # dom-selection-stringifier |
浏览器兼容性
加载中…
另见
Selection,它所属的接口。