当前位置:网站首页>Clipboard tutorial
Clipboard tutorial
2022-06-25 14:28:00 【Enlightened gentleman】
clipboard Is to achieve the function of copying text to the clipboard JavaScript plug-in unit , It is very convenient to realize the copy and cut function
Official website address :https://clipboardjs.com/
1、 Copy
(1)、 Copy the contents of the input box
adopt data-clipboard-target Property to specify what to copy
adopt data-clipboard-action Property to perform the type of operation ,copy For replication
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/clipboard.min.js" ></script>
</head>
<body>
<div>
<textarea id="bar"> The Yellow River is far above the white clouds </textarea>
<button class="btn" data-clipboard-action="copy" data-clipboard-target="#bar">
Copy
</button>
<br>
<input type="text" />
</div>
<script>
var clipboard = new ClipboardJS('.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);
});
</script>
</body>
</html>
Running effect

(2)、 Copy the specified value
In the structure ClipboardJS When , Specify the copied text
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/clipboard.min.js" ></script>
</head>
<body>
<div>
<button id="copy">
Copy
</button>
<br>
<input style="width: 400px;" type="text" />
</div>
<script>
var clipboard = new ClipboardJS('#copy', {
text: function(trigger) {
return ' Looking for the floor in front of the window , Plant a plum . The moon and the breeze I , The world of mortals will never return .';
}
});
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);
});
</script>
</body>
</html>
Running effect

2、 shear
adopt data-clipboard-action Property to perform the type of operation ,cut To cut
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type="text/javascript" src="js/clipboard.min.js" ></script>
</head>
<body>
<div>
<textarea id="bar"> Outside the window, Yan Jiaoying is jealous . There is no evidence for the dream soul under the window . Dreams are good but often startled , Not to the depths of the clouds . No thread . No thread . Red heavy curtain of rain .</textarea>
<button class="btn" data-clipboard-action="cut" data-clipboard-target="#bar">
shear
</button>
<br>
<input style="width: 580px;" type="text" />
</div>
<script>
var clipboard = new ClipboardJS('.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);
});
</script>
</body>
</html>
Running effect

That's it
边栏推荐
- oracle数据库常用的函数总结
- 分享自己平时使用的socket多客户端通信的代码技术点和软件使用
- ‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件
- Tencent cloud builds a Socks5 multi IP proxy server to realize the perfect building of a game with a single window and a single IP. Tutorial attached tool "suggestions collection"
- 电脑必须打开的设置
- TSDB在民机行业中的应用
- Where is it safe to open an account for buying funds? Ask for guidance
- laravel8实现图片验证码
- 112页机器学习-数学基础回顾.pptx
- Shell built-in commands
猜你喜欢

两种方法实现pycharm中代码回滚到指定版本(附带截图展示)

Dialogue: recommended system quick start route and summary of knowledge points

Application of TSDB in civil aircraft industry

Problems encountered in debugging botu TCP connection with debugging tool

电脑必须打开的设置

让PyTorch训练速度更快,你需要掌握这17种方法

API encapsulation of uniapp applet

程序員為什麼要軟一點?

中国电池技术取得重大突破,日韩美都落后了,中国巩固了领先优势

‘nvidia-smi‘ 不是内部或外部命令,也不是可运行的程序或批处理文件
随机推荐
Share the code technology points and software usage of socket multi client communication
分享自己平时使用的socket多客户端通信的代码技术点和软件使用
None of the MLIR Optimization Passes are enabled (registered 2)解决办法
Basic usage of markdown (plain text and grammar)
Network remote access using raspberry pie
Let and const commands
中国电池技术取得重大突破,日韩美都落后了,中国巩固了领先优势
如何在 2022 年为 Web 应用程序选择技术堆栈
PubSub JS library realizes "cross component" data transfer
Summary of common functions in Oracle Database
Les neuf caractéristiques de la parole et les neuf temps en anglais
JS determines whether two values are equal, and compares any two values, including array objects
Common formatting methods for amount numbers
Is it safe for tongdaxin to open a stock account
关于STM32使用LAN8720A插拔网线重连
shell 字符串变量
完整详细的汇编实验报告
Kubernetes 理解kubectl/调试
'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file
shell 运算符