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 ...
随机推荐
- 自己第一次使用ANTLR遇到的问题
觉得既然是第一次尝试ANTLR嘛,那就来个简单点的,parse Windows 的 hosts 文件吧,结果...... 先上一段 grammar: grammar hosts; hostfile: ...
- 计算机专业C语言编程学习重点:指针化难为易
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- drag element
<div id="logDiv" draggable="true" style="border: 2px dotted red; width: ...
- C语言复习20170821
函数 函数头部参数表里的变量称为形参,也是内部变量,只能在函数体内访问. 形参的作用是实现主调函数与被调函数之间的联系,通常将函数所处理的数据,影响函数功能的因素或者函数处理的结果作为形参.没有形参的 ...
- win10-MySql免安装版-安装/多实例
一.MySql免安装版安装: 1.MySql分为两个版本: 安装板的msi格式文件,直接点击下一步,下一步就可以安装 免安装版的zip格式,直接解压配置安装即可,[解压-初始化创建data目录-创建用 ...
- mybatis逆向工程 mbg运行java代码时提示找不到MBG.xml的解决方法
这里要写全路径才能找到文件
- 数据库路由中间件MyCat - 源代码篇(15)
此文已由作者张镐薪授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. public static void handle(String stmt, ServerConnectio ...
- pyqt5实现SMTP邮件发送
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'SMTP.ui' # # Created b ...
- 产品需求文档(PRD)的写作 【转】
产品需求文档(PRD)的写作 一.文章的摘要介绍 无论我们做什么事都讲究方式方法,写产品需求文档(以下称PRD文档)也是如此,之前我通过四篇文章分享了自己写PRD文档的一些方法,而这一篇文章主要是 ...
- 每天一个linux命令集
linux命令汇总,装载来自: http://www.cnblogs.com/peida/category/309012.html