当前位置:网站首页>ClipboardJS——开发学习总结1
ClipboardJS——开发学习总结1
2022-06-30 11:22:00 【Mr_LiuP】
问题需求描述:
由于是公司内部app,无法在app内复制、甚至截图,涉及安全隐私。
app内嵌H5页面,通过使用复制按钮,实现文本复制!
解决方法:
ClipboardJS,一款将文本复制到剪贴板的js插件,不使用flash,最小仅3k
1.使用方式:
npm安装:npm i clipboard --save
CDN安装:<script src="dist/clipboard.min.js"></script>
2.创建clipboard.js实例,通过传递 DOM 选择器、HTML 元素或 HTML 元素列表创建
<div id="temp_text">我是需要被复制的文字</div>
<button class="copy_btn" data-clipboard-target="#temp_text">一键复制</button>
var clipboard = new Clipboard('.copy_btn');
clipboard.on('success', function(e) {
console.info('Action:', e.action);
console.info('Text:', e.text);
console.info('Trigger:', e.trigger);
e.clearSelection();
});
clipboard.on('error', function(e) {
console.error('Action:', e.action);
console.error('Trigger:', e.trigger);
});
3. 其他属性说明
data-clipboard-target:触发器元素的 data-clipboard-target 属性中包含的值需要与另一个元素的选择器相匹配
<div id="temp_text">我是需要被复制的文字</div>
<button class="copy_btn" data-clipboard-target="#temp_text">一键复制</button>
data-clipboard-text:不一定非要从另一个元素复制其内容。 也可以只在触发器元素中包含一个 data-clipboard-text 属性并复制该属性的内容
<button class="copy_btn" data-clipboard-text="我是被复制的文字">我复制我自己属性里的文字</button>
data-clipboard-action:指定是要复制还是剪切内容,值为 cut 表示执行剪切操作。如果省略此属性,默认情况下将使用复制
<div id="temp_text">我是需要被复制的文字</div>
<button class="copy_btn" data-clipboard-target="#temp_text" data-clipboard-action="cut">一键剪切</button>
边栏推荐
- 10 reasons for system performance failure
- 科普達人丨漫畫圖解什麼是eRDMA?
- The latest collection of arouter problems
- Xu Lei expressed three thanks for the most difficult 618 in 19 years
- Alibaba cloud lifeifei: China's cloud database has taken the lead in many mainstream technological innovations abroad
- Summer vacation study record
- In depth analysis of Apache bookkeeper series: Part 4 - back pressure
- A quietly rising domestic software, low-key and powerful!
- CVPR 2022 | 大幅减少零样本学习所需人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入...
- 暑假学习记录
猜你喜欢

阿里云李飞飞:中国云数据库在很多主流技术创新上已经领先国外

R语言查看版本 R包查看版本

“新数科技”完成数千万元A+轮融资,造一体化智能数据库云管理平台

CVPR 2022 | 大幅减少零样本学习所需人工标注,马普所和北邮提出富含视觉信息的类别语义嵌入...

If it is not listed again, Kuangshi technology will not be able to endure

科普達人丨漫畫圖解什麼是eRDMA?

关于IP定位查询接口的测评Ⅲ

1175. prime permutation

Dameng data rushes to the scientific innovation board, or becomes the "first share of domestic database" in the A-share market

ESP32-C3入门教程 问题篇⑨——Core 0 panic‘ed (Load access fault). Exception was unhandled. vfprintf.c:1528
随机推荐
How to analyze native crash through GDB
考研这些“不靠谱”的经验有多害人?
AMS source code analysis
他是上海两大产业的第一功臣,却在遗憾中默默离世
Digitalization is not a trial, but a wading out of "Xingzhi Digital China" × History of Foxconn
Database cascading operation
Methods and usage of promise async and await
Esp32-c3 introductory tutorial basic part ⑪ - reading and writing non-volatile storage (NVS) parameters
100 important knowledge points that SQL must master: using stored procedures
Retest the cloud native database performance: polardb is still the strongest, while tdsql-c and gaussdb have little change
Compression state DP bit operation
限时预约|6 月 Apache Pulsar 中文开发者与用户组会议
Discussion on the essence of "FPGA mining" from open source projects
Who still remembers "classmate Zhang"?
Pointdistiller: structured knowledge distillation for efficient and compact 3D detection
脚本中如何'优雅'避免MySQL登录提示信息
Mathematics (fast power)
一个人就是一本书
10 reasons for system performance failure
MCU firmware packaging Script Software