替换所选文本(Firefox)

news/2024/7/19 16:37:25 标签: 字符串, python, php, javascript, js

A quick function to replace the selected text (in Firefox). Accepts:

替换所选文本的快速功能(在Firefox中)。 接受:

  • string to replace the selection, or

    字符串来替换选择,或者
  • callback function that takes the selected text and returns a string to replace the selection

    带有所选文本并返回字符串以替换所选内容的回调函数
function replaceSelection(t) {
  if (typeof t === 'function') {
    t = t(window.getSelection().toString());
  }
  var range = window.getSelection().getRangeAt(0);
  range.deleteContents();
  range.insertNode(document.createTextNode(t));
}

Usage:

用法:

1. Replace selected text with "dude" replaceSelection('dude'); 2. Uppercase the selected text replaceSelection(function(s){return s.toUpperCase()}); 3. Lowercase the selected text replaceSelection(function(s){return s.toLowerCase()});

1.将所选文本替换为“ dude” replaceSelection('dude'); 2.大写所选文本replaceSelection(function(s){return s.toUpperCase()}); 3.小写所选文本replaceSelection(function(s){return s.toLowerCase()});

Luckily I'm so close (and yet so far) to finishing this book, otherwise I won't be able to help myself but create a whole toolbar of bookmarklets for "power" Google doc users...

幸运的是,我已经很接近(到目前为止)完成本书,否则我将无法为自己服务,而是为“强大”的Google文档用户创建了一个完整的书签小工具栏...

Tell your friends about this post on Facebook and Twitter

在Facebook和Twitter上告诉您的朋友有关此帖子的信息

翻译自: https://www.phpied.com/replace-selected-text-firefox/


http://www.niftyadmin.cn/n/1306416.html

相关文章

执行请求的操作时遇到错误

执行请求的操作时遇到错误 1、具体错误如下: ORA-01017:invalid username/password:logon denied 01017. 00000 -"invalid username/password.logon denied " *Cause: *Action: 2、错误原因 输入的密码不正确 3、解决办法 查看数据库配置文件,…

word编辑——制位表

使用多级列表时,要求自动编号后面空2格,使用制表符,比如三级标题,文本缩进和对齐位置都选0,然后左对齐,点更多,三级标题选制表符,直接输2个字符或者0.71cm,二级标题需要输…

js 画布翻转_将照片加载到画布中,然后翻转

js 画布翻转Today our family went to the yearly photo session with the girls. We took one shot that can be looked normally, as well as upside down, so I was wondering can you flip an image using a canvas tag. Turns out, yes, you can and its pretty easy. 今…

Excel 2010高级应用-雷达图(六)

Excel 2010高级应用-雷达图(六) 基本操作如下: 1、新建空白Excel文档,并命名雷达图 2、单击“插入”,并找到雷达图图样 3、单击雷达图图样,在空白文档上生成图框,并在图框下方生成数据源 4、在图…

推荐几个免费的电子书下载网站——网盘版

推荐几个免费的电子书下载网站——网盘版 1:虫部落 搜素引擎的集合版 链接: link. 图片: 2.大圣盘,类似于大力盘,怀疑它们的引擎是一个,搜索结果可能内它丰富 链接:link 图片: 3.罗马盘&am…

Excel 2010高级应用-圆环图(七)

Excel 2010高级应用-圆环图(七) 基本操作如下: 1、新建空白Excel文档,并命名为圆环图 2、单击“插入”,并找到圆环图图样 3、单击圆环图图样,并在空白文档上生成图框 4、在图框下方生成数据源 5、在图框上方…

写作技巧合集

A collection of writing tips here, includes advise from Stephen King, Paul Graham, Scott Adams and others. 这里的写作技巧集合包括Stephen King,Paul Graham,Scott Adams等人的建议。 In the end, if you want to write well I believe it all b…

idm下载磁力

idm推荐 自动注册版 度娘链接 密码:ekwc 黑科下载器 原理大概是将磁力链接的电影或者文件下载到它们自己的服务器,然后提供一个链接进行下载,很多链接提示版权有限或者违禁,一般的热门的电影电视剧大概都能下载。点击其中的磁…