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 ...
随机推荐
- 20155339 2016-2017-2 《Java程序设计》第3周学习总结
20155339 2016-2017-2 <Java程序设计>第3周学习总结 教材学习内容总结 第四章 认识对象 类与对象 1.定义类时使用class关键词再加名称,例如 class Cl ...
- sougoupinyin for linux 安装步骤(精简版)
download deb double-click to install select fcitx reboot click it in the bar and choose the"tex ...
- Potree学习总结
一. 简介 基于Web端的三维模型展示,这里仅介绍Three.js和Potree. Three.js 是一款基于WebGL的运行在浏览器中的 3D 开源引擎,用它创建各种三维场景.它类似于M ...
- RHSCA模拟考试
开始考试:桌面是个黑框子 点击reboot按钮,破解密码 开机成功,输入startx进入图形界面 不能复制,要在物理机用ssh root@172.25.0.11 远程连接,就可以复制粘贴了 * Hos ...
- day2 CSS- 选择器
1.CSS 语法 css是英文Cascading Style Sheets的缩写,称为层叠样式表 2.css的四种引入方式 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现 ...
- wpf TabControl控件的SelectionChanged方法
对于老手来说很简单,但是新手我从百度上找了好久没找到,最后还是去谷歌找到的,哎,万能的google. 前端界面: <TabControl Margin="0,10,0,0" ...
- R的数据结构
R语言中的数据结构包括标量.向量.矩阵.数组.列表以及数据框 目录 1 向量 2 矩阵 3 数据框 1 向量 向量是用于存储单一数据类型(数值.字符.逻辑值)的一维数组,示例如下: a <- c ...
- 使用Nexus搭建Maven私服问题总结
#业务场景 最近项目要交付给客户了,之前项目开发和测试一直都是使用公司内部的一套环境,项目交付后客户购置了大量服务器,也要将整套测试环境迁移至客户的服务器上,后续的需求变更以及新需求的开发都会在客户服 ...
- 【MongoDB安装】MongoDB在centos linux平台安装
参考:http://www.runoob.com/mongodb/mongodb-linux-install.html 一..下载安装包 下载方式: 1.登录官网download,然后通过xftp传到 ...
- 强化学习读书笔记 - 12 - 资格痕迹(Eligibility Traces)
强化学习读书笔记 - 12 - 资格痕迹(Eligibility Traces) 学习笔记: Reinforcement Learning: An Introduction, Richard S. S ...