JavaScript 获得选中文本内容的方法
时间:2024-05-03 15:07:18
有如下实现方法:
在Firefox, Google Chrome, Safari, Opera中:可以用 window.getSelection() (参考MDC)
在IE下,可以用 document.selection.createRange().text (参考MSDN)
注:将两者放在一起的代码:
function getSelectionText() {
if(window.getSelection) {
return window.getSelection().toString();
} else if(document.selection && document.selection.createRange) {
return document.selection.createRange().text;
}
return '';
}
标签:JavaScript,选中文本内容
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python批量生成幻影坦克图片实例代码
2021-04-17 03:16:17
![](https://img.aspxhome.com/file/2023/3/81473_0s.png)
Python随机函数库random的使用方法详解
2021-06-07 16:16:23
![](https://img.aspxhome.com/file/2023/6/70106_0s.png)
Python 获取windows桌面路径的5种方法小结
2023-04-01 09:06:47
python实现QQ邮箱/163邮箱的邮件发送
2022-12-12 14:07:15
![](https://img.aspxhome.com/file/2023/2/92462_0s.png)
用python统计代码行的示例(包括空行和注释)
2022-06-28 02:15:30
Pytorch转keras的有效方法,以FlowNet为例讲解
2023-07-27 02:04:54
MySQL查询重写插件的使用
2024-01-27 15:55:58
![](https://img.aspxhome.com/file/2023/6/121546_0s.jpg)
python爬虫开发之使用Python爬虫库requests多线程抓取猫眼电影TOP100实例
2021-02-25 11:13:42
![](https://img.aspxhome.com/file/2023/9/99519_0s.png)
详解Python中的Array模块
2021-11-14 02:14:27
在 Windows 下搭建高效的 django 开发环境的详细教程
2023-08-31 06:14:12
![](https://img.aspxhome.com/file/2023/2/121782_0s.png)
Python制作春联的示例代码
2022-12-10 13:57:23
![](https://img.aspxhome.com/file/2023/7/131437_0s.jpg)
详解Ubuntu16.04安装Python3.7及其pip3并切换为默认版本
2023-07-30 10:18:13
![](https://img.aspxhome.com/file/2023/0/92400_0s.png)
Python光学仿真理解Jones矩阵学习
2022-03-10 21:11:39
![](https://img.aspxhome.com/file/2023/6/81746_0s.png)
JavaScript之解构赋值的理解
2024-04-10 10:44:07
![](https://img.aspxhome.com/file/2023/0/136980_0s.png)
MySQL表类型 存储引擎 的选择
2024-01-22 08:12:51
php发送get、post请求的6种方法简明总结
2023-11-14 12:59:43
python一行输入多值的实现详解
2021-07-02 06:52:39
![](https://img.aspxhome.com/file/2023/0/124180_0s.png)
python读写文件write和flush的实现方式
2022-10-28 07:04:58
DjangoRestFramework 使用 simpleJWT 登陆认证完整记录
2021-03-29 18:34:12
![](https://img.aspxhome.com/file/2023/1/76001_0s.png)
利用Python多处理库处理3D数据详解
2021-03-05 18:11:18
![](https://img.aspxhome.com/file/2023/7/101267_0s.jpg)