js get selected text
js get selected text
https://stackoverflow.com/questions/3170648/how-to-get-javascript-select-boxs-selected-text
http://www.javascriptkit.com/javatutors/copytoclipboard.shtml
const getSelectionText = () => {
let selectedText = ``;
if (window.getSelection){
// all modern browsers and IE9+
let selection = window.getSelection();
console.log(`selection =`, selection);
selectedText = window.getSelection().toString();
console.log(`you selected text =`, selectedText);
let selectedTextWithTrim = window.getSelection().toString().trim();
console.log(`you selected text with trim() =`, selectedTextWithTrim);
}
return selectedText;
};
// getSelectionText();

<!DOCTYPE html>
<html lang="zh-Hans">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="xgqfrms">
<meta name="generator" content="VS code">
<title></title>
</head>
<body>
<section>
<h1></h1>
<a href="https://feiqa.xgqfrms.xyz/index.html"></a>
</section>
<!-- js -->
<script>
const getSelectionText = () => {
let selectedText = ``;
if (window.getSelection){
// all modern browsers and IE9+
let selection = window.getSelection();
console.log(`selection =`, selection);
selectedText = window.getSelection().toString();
console.log(`you selected text =`, selectedText);
let selectedTextWithTrim = window.getSelection().toString().trim();
console.log(`you selected text with trim() =`, selectedTextWithTrim);
}
return selectedText;
};
// getSelectionText();
</script>
</body>
</html>
js get selected text的更多相关文章
- js中的text(),html() ,val()的区别
js中的text(),html() ,val()的区别 text(),html() ,val()三个方法用于html元素的存值和取值,但是他们各有特点,text()用于html元素文本内容的存取,ht ...
- jQuery get selected text from SELECT (or DROPDOWN) list box
Most of the time in JavaScript we want to do following things with Select (or dropdown) list box. – ...
- WordLight: highlights all occurrences of a selected text for VS2008
https://visualstudiogallery.msdn.microsoft.com/ad686131-47d4-4c13-ada2-5b1a9019fb6f About This is a ...
- Selenium Webdriver——JS处理rich text(富文本框)
126邮件正文邮件的rich text 先让selenium切换到iframe中 driver.switchTo().frame(driver.findElement(By.className(&qu ...
- Js script type="text/template"的使用简单说明
<script type="text/template" id="treeTableTpl"> <tr id="{{row.id}} ...
- 微信小游戏 Three.js UI 2D text 简单方案
在微信小游戏中使用 THREE.js 引擎,没有合适的 UI 库可用,只能自己动手.图片啥的都还好,text 不好弄.text 要计算 width 和 height,不然事件响应范围不对. funct ...
- js控制input text字符键入/字符长度限制/字母自动大写
功能: 1.仅允许指定字符键入 2.限制长度 实现代码: <input type="text" style="width: 6em" name=" ...
- JS Radio结合TEXT
<script> function fun_a(value){ if(value === "on"){ document.getElementById('a').dis ...
- Copy Selected Text from any window
https://social.msdn.microsoft.com/Forums/windows/en-US/1dc356e6-9441-44de-9eda-247003fa6ef5/copy-sel ...
随机推荐
- cogs930找第k小的数(k-th number)
cogs930找第k小的数(k-th number) 原题链接 题解 好题... 终极版是bzoj3065(然而并不会) 先讲这个题... 维护\(n+1\)个值域线段树(用主席树),标号\(0\) ...
- sklearn半监督学习
标签: 半监督学习 作者:炼己者 欢迎大家访问 我的简书 以及 我的博客 本博客所有内容以学习.研究和分享为主,如需转载,请联系本人,标明作者和出处,并且是非商业用途,谢谢! --- 摘要:半监督学习 ...
- 接口文档神器Swagger(下篇)
本文来自网易云社区 作者:李哲 二.Swagger-springmvc原理解析 上面介绍了如何将springmvc和springboot与swagger结合,通过简单配置生成接口文档,以及介绍了swa ...
- Mybatis传递参数的三种方式
第一种: Dao层使用@Param注解的方法 VersionBox getVersionByVersionNumAndVersionType(@Param("versionNum" ...
- 基于ejabberd实现各个客户端消息同步
先上图再说(左侧是web端,右侧是ios端) 要实现上面的功能,如果所有设备都在线的话,那么carboncopy(xmpp xep-0280协议)这个模块是可以实现接收到的消 ...
- 基于Spring的最简单的定时任务实现与配置(三)--番外篇 cron表达式的相关内容
本来这篇文章是会跟本系列的前两篇文章一起发布的.但是,昨天在找资料总结的时候遇到了一点意外,就延后了一些. 本篇的内容主要参考了 这篇博文:http://www.cnblogs.com/junrong ...
- Ubuntu设置DNS服务
有时候安装完Ubuntu系统,源换好好还是不能更新,软件也不能下, 配置好IP,ping 1.1.1.1是通的,ping 域名就不通了,这是没有DNS解析域名的结果 一.Server版: 对于Ubun ...
- EasyUI validatebox 自定义ajax验证用户名是否已存在
<td><input type="text" id="userName" name="userName" class=&q ...
- 无法找到 ContextLoaderListener 类
问题:java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener 原因:Eclips ...
- Yii2 UploadedFile上传文件
通过 UploadFile::getInstance($model, $attribute); UploadFile::getInstances($model, $attribute); Upload ...